如何知道,如果一个机器人动作条的操作图标在顶部栏或底栏(分)? [英] How to know if an Android actionbar's action icon is on the top bar or the bottom bar (split)?

查看:141
本文介绍了如何知道,如果一个机器人动作条的操作图标在顶部栏或底栏(分)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个拆分操作栏,其中最上面一栏是黑暗和底栏(分)亮。

I have a split action bar, where the top bar is dark and the bottom bar (split) is light.

因此​​,我想表现出相反的动作图标:光图标在顶部暗杆和暗的图标在底部的灯条

Consequently, I'd like to show a contrast action icons: Light icons in the top dark bar and dark icons in the bottom light bar.

这个问题是要知道,如果行动应涂在顶部或底部的条形码。我怎么能知道?

The problem is knowing if the actions should be painted on the top or bottom bar. How can I know that?

另一种选择是知道操作栏当前是否分裂。我怎么知道?

Another option is to know whether the action bar is currently split. How do I know that?

感谢。

推荐答案

简单。您可以使用布尔值。默认情况下,你将有一个分裂的ActionBar如果屏幕宽度小于400dp小。因此,在你的价值观文件夹,你可以把:

Simple. You use boolean values. By default you'll have a split ActionBar if the screen width is smaller than 400dp. So in your values folder you can put:

/values​​/bools.xml:

<resources>
    <bool name="split_action_bar">true</bool>
</resources>

和你的价值观sw400dp你把下面的内容。

and in your values-sw400dp you put the following.

/values​​-sw400dp/bools.xml:

<resources>
    <bool name="split_action_bar">false</bool>
</resources>

现在,您可以根据该值设置你的图标:

Now you can set your icon based on that value:

boolean isActionBarSplitted = getResources().getBoolean(R.bool.split_action_bar);
if(isActionBarSplitted){
      // set light icon
}
else{
     // set dark icon
}

编辑:

其实忘了我写的,你不需要创建自己的布尔值进行检查。已经有一个所声明的(这是一个在ActionBar使用以确定它是否是一个手持通话器设备或片剂)。 如果您定位的Andr​​oid HC +,那么你就可以访问缺省值其他动作: android.R.bool.split_action_bar_is_narrow ,如果您使用的是ActionBarSherlock: R.bool.abs_split_action_bar_is_narrow 。 找到<一href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/bools.xml">here默认动作条,<一href="https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/res/values/abs__bools.xml">here你的腹部。

Actually forget what I wrote, you don't need to create your own boolean value to check it. There is already one declared(which is the one the ActionBar uses to determine if it is a handset device or a tablet). If you're targeting Android HC+, then you can access the default ActionBars value: android.R.bool.split_action_bar_is_narrow, if you are using ActionBarSherlock: R.bool.abs_split_action_bar_is_narrow. Found here for the default ActionBar, here your ABS.

这篇关于如何知道,如果一个机器人动作条的操作图标在顶部栏或底栏(分)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆