Android setDisplayOptions 具体的使用说明
2015-09-16 13:12
786 查看
Android有几个地方使用位计算。实例Intent Flags,它们的定义View onMeasure(int widthMeasureSpec, int heightMeasureSpec),并且ActionBar setDisplayOptions ,以下就理解一下setDisplayOptions的使用方法。
先看下文档中对他的描写叙述:
Added in API level 11
Set display options. This changes all display option bits at once. To change a limited subset of display options, see
Parameters
一次性设置选项这种方法。假设要设置部分。那么使用以下的方法
Added in API level 11
Set selected display options. Only the options specified by mask will be changed. To change all display option bits at once, see
Example: setDisplayOptions(0, DISPLAY_SHOW_HOME) will disable the
setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO) will enable
disable
Parameters
选择部分来显示设置,仅仅有当options在mask中被设置才干被显示。也就是设置为true。
那么问题来了。。。
究竟怎么用options 和mask尼?看以下内容
ActionBar默认假设没有做不论什么设置,会显示出一个箭头(DISPLAY_HOME_AS_UP),一个logo(DISPLAY_SHOW_HOME),标题(DISPLAY_SHOW_TITLE)
一旦使用setDisplayOptions(int options)这种方法,全部的设置项都变成了false,options使用或运算加入设置。加入一个就设置一个为true-显示,比方setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM),就是设置显示返回箭头和customView
setDisplayOptions(int options,int mask)方法,即在当前默认的ActionBar设置项内。选择几个来设置。这种场景可能是Activity内部的Fragment。须要给Fragment设置ActionBar的几个确定选项,比方
mask为 ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM
mask和options中都有ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM。那么就是把箭头和customView设置为显示,mask中剩下的ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME 就设置为隐藏。即相应的setDisplayShowTitleEnabled(false),其它没有提到的选项就应该为默认的配置。
能够这样理解。mask和option运行了&运算,同一时候出现的为true,出现一个的为false。
知道了原理我们就能够这样用,比方我们仅仅要显示a,b,c三个选项,
那么就使用getSupportActionBar().setDisplayOptions(
a|b|c );
假设我们在特定的条件下,比方fragment中,须要仅仅对b,c,d这三个选项进行设置,把b。c设置为显示。d设置为隐藏,那么就能够使用getSupportActionBar().setDisplayOptions(b|c
, b|c|d );
用了这种方法就不须要一个一个的设置setDisplayShowXXX()了
了解很多其它能够去:/article/2494830.html
先看下文档中对他的描写叙述:
public abstract void setDisplayOptions (int options)
Added in API level 11Set display options. This changes all display option bits at once. To change a limited subset of display options, see
setDisplayOptions(int, int).
Parameters
options | A combination of the bits defined by the DISPLAY_ constants defined in ActionBar. |
---|
public abstract void setDisplayOptions (int options, int mask)
Added in API level 11Set 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_HOMEoption.
setDisplayOptions(DISPLAY_SHOW_HOME, DISPLAY_SHOW_HOME | DISPLAY_USE_LOGO) will enable
DISPLAY_SHOW_HOMEand
disable
DISPLAY_USE_LOGO.
Parameters
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尼?看以下内容
ActionBar默认假设没有做不论什么设置,会显示出一个箭头(DISPLAY_HOME_AS_UP),一个logo(DISPLAY_SHOW_HOME),标题(DISPLAY_SHOW_TITLE)
一旦使用setDisplayOptions(int options)这种方法,全部的设置项都变成了false,options使用或运算加入设置。加入一个就设置一个为true-显示,比方setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM),就是设置显示返回箭头和customView
setDisplayOptions(int options,int mask)方法,即在当前默认的ActionBar设置项内。选择几个来设置。这种场景可能是Activity内部的Fragment。须要给Fragment设置ActionBar的几个确定选项,比方
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
mask为 ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM
mask和options中都有ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM。那么就是把箭头和customView设置为显示,mask中剩下的ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME 就设置为隐藏。即相应的setDisplayShowTitleEnabled(false),其它没有提到的选项就应该为默认的配置。
能够这样理解。mask和option运行了&运算,同一时候出现的为true,出现一个的为false。
知道了原理我们就能够这样用,比方我们仅仅要显示a,b,c三个选项,
那么就使用getSupportActionBar().setDisplayOptions(
a|b|c );
假设我们在特定的条件下,比方fragment中,须要仅仅对b,c,d这三个选项进行设置,把b。c设置为显示。d设置为隐藏,那么就能够使用getSupportActionBar().setDisplayOptions(b|c
, b|c|d );
用了这种方法就不须要一个一个的设置setDisplayShowXXX()了
了解很多其它能够去:/article/2494830.html
相关文章推荐
- Android Multiple APK Support
- android 内存优化
- Android v4 包和v7包问题
- Android开发之仿联系人界面(根据文字首字母A、B、C实现快速索引)
- 性能优化之Traceview工具的使用
- android RotateAnimation设置中心点旋转动画
- Android开发之QQ空间效果(QQ空间下拉图片放大,松手后回弹)
- Android开发之QQ侧滑面板
- Android(java)学习笔记259:JNI之NDK开发步骤
- android事件传递机制
- Android 获取 Mac地址
- 深入浅出 - Android系统移植与平台开发(八)- HAL Stub框架分析
- Android list 泛型 用Gson 转json字符串 出现 java.lang.StackOverflowError异常解决
- Android的相关的源代码的方法
- Android普通对话框用法实例分析
- Android多线程通信之Handler
- Android 不要把android做成ios!
- android开发不继承ActionBarActivity直接继承Activity的方法
- android选择图片进行裁剪
- Android Studio Tips & Tricks: Moving Around