Android setDisplayOptions 具体的使用说明

Android setDisplayOptions 具体的使用说明

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

  Android有几个地方使用位计算。实例Intent Flags,它们的定义View onMeasure(int widthMeasureSpec, int heightMeasureSpec),并且ActionBar setDisplayOptions ,以下就理解一下setDisplayOptions的使用方法。

  先看下文档中对他的描写叙述:

public abstract void setDisplayOptions (int options)

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 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 11

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.

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中被设置才干被显示。也就是设置为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的几个确定选项,比方

 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()了

了解很多其它能够去:http://blog.csdn.net/zzp16/article/details/7956768








版权声明:本文博主原创文章。博客,未经同意不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117026.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 移动通信网络架构的演进过程_移动通信演进路线图

    移动通信网络架构的演进过程_移动通信演进路线图原文地址:http://blog.sina.com.cn/s/blog_64827e4c010105nl.html

    2022年9月21日
    3
  • jadxgui反编译教程_apktool工具反编译apk

    jadxgui反编译教程_apktool工具反编译apk可以直接在GitHub上:https://github.com/skylot/jadx.git找到反编译工具jadx-gui源码,在windows电脑:(电脑上已经有git命令工具)gitclonehttps://github.com/skylot/jadx.git然后打开cmd命令窗口:进入到gitclone下来的文件所在的文件路径下,cdE:\jadx之后运行:gra…

    2025年7月30日
    5
  • 如何下载pycharm以前的版本_pycharm版本区别

    如何下载pycharm以前的版本_pycharm版本区别地址:https://www.jetbrains.com/pycharm/download/previous.html点击进去就能看到各个版本的下载链接。

    2022年8月25日
    5
  • CTK框架使用

    CTK框架使用基于Qt的CTK框架的使用QT的plugin插件的创建方式在介绍CTK框架的使用方法之前我们首先介绍一下QT的plugin插件的创建方式。QT提供两种API来创建插件:扩展Qt库本身的高级API。例如:定制databasedrivers,imageformats,textcodecs,customstyles,etc.扩展应用程序的低级API如果你像创建一个可以在QtDes

    2022年6月6日
    151
  • HDP kt_renewer ERROR Couldn‘t renew kerberos ticket in order to work around Kerberos 1.8.1 issu

    HDP kt_renewer ERROR Couldn‘t renew kerberos ticket in order to work around Kerberos 1.8.1 issu完整报错:kt_renewerERRORCouldn’trenewkerberosticketinordertoworkaroundKerberos1.8.1issue.Pleasecheckthattheticketfor’hue/client-v01.16899.com@16899.COM’isstillrenewable:

    2025年7月14日
    2
  • nginx反向代理服务contextpath的问题解决

    nginx反向代理服务contextpath的问题解决文章目录问题描述解决方案 sub filter 方案使用重定向单独域名访问问题描述现在的企业服务 往往不是单体的 同时可能涉及中间件的访问如 dubbo solr mq 等 对于中间件的监控页面访问 如果直接暴露在公网 肯定这安全 需发对中间件访问进行安全加固 方法主要有 1 限制使用 IP 白名单访问 2 安全密码访问 不使用简单密码 对于没有密码的 可以使用 basic 认证 强密码访问 3

    2025年7月11日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号