标签:des android style blog http io color ar 使用
Android中有几个地方用到了位运算,比如Intent Flags,自定义View onMeasure(int widthMeasureSpec, int heightMeasureSpec),还有ActionBar setDisplayOptions ,下面就理解一下setDisplayOptions的用法。
先看下文档中对他的描述:
Set display options. This changes all display option bits at once. To change a limited subset of display options, see setDisplayOptions(int,
int)
.
options | A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
---|
Set selected display options. Only the options specified by mask will be changed. To change all display option bits at once, see setDisplayOptions(int)
.
Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the DISPLAY_SHOW_HOME
option.
setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO) will enable DISPLAY_SHOW_HOME
and
disable DISPLAY_USE_LOGO
.
options | A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
---|---|
mask | A bit mask declaring which display options should be changed. |
选择部分来显示设置,只有当options在mask中被设置才能被显示,也就是设置为true。
那么问题来了。。。
到底怎么用options 和mask尼?看下面内容
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM);options为 ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM
知道了原理我们就可以这样用,比如我们只要显示a,b,c三个选项,
那么就使用getSupportActionBar().setDisplayOptions( a|b|c );
如果我们在特定的条件下,比如fragment中,需要只对b,c,d这三个选项进行设置,把b,c设置为显示,d设置为隐藏,那么就可以使用getSupportActionBar().setDisplayOptions(b|c , b|c|d );
用了这个方法就不需要一个一个的设置setDisplayShowXXX()了
了解更多可以去:http://blog.csdn.net/zzp16/article/details/7956768
Android setDisplayOptions 的用法详解
标签:des android style blog http io color ar 使用
原文地址:http://blog.csdn.net/mobilexu/article/details/41147417