ActionBar的基本属性

ActionBar Displayoptions
  • displayoptions这个属性主要是控制ActionBar上面的返回按钮以及标题的显示
  • 使用
 <style name="ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
     <item name="android:displayOptions">showCustom|disableHome|showTitle|homeAsUp|</item>
 </style>
 
 
setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));
ActionBar Displayoptions属性值
  • ActionBar.DISPLAY_USE_LOGO = 0x1
  • ActionBar.DISPLAY_SHOW_HOME = 0x2
  • ActionBar.DISPLAY_HOME_AS_UP = 0x4
  • ActionBar.DISPLAY_SHOW_TITLE = 0x8
  • ActionBar.DISPLAY_SHOW_CUSTOM = 0x10
  • ActionBar.DISPLAY_TITLE_MULTIPLE_LINES
Displayoptions属性的对应方法
Displayoptions属性名意义
DISPLAY_USE_LOGOsetDisplayUseLogoEnabled()显示app品牌的标志比如youtube
DISPLAY_SHOW_HOMEsetDisplayShowHomeEnabled()控制左上角图标是否显示,如果设置成false 泽只有标题,设置为true, 显示应用程序的图标对应R.id.home
DISPLAY_HOME_AS_UPsetDisplayHomeAsUpEnabled()给左上角图标的左边加上返回键
DISPLAY_SHOW_TITLEsetDisplayShowTitleEnabled()控制标题是否显示
DISPLAY_SHOW_CUSTOMsetDisplayShowCustomEnabled()自定义的view可以在title显示使得setCustomView可以起作用
与DISPLAY_SHOW_HOME一起使用setHomeButtonEnabled()决定左上角的图标是否可以点击
setDisplayUseLogoEnabled()
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_action_bar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setLogo(R.drawable.arraw);
}
setDisplayShowHomeAsUpEnabled()
  • 显示左上角返回按钮并且可点击
@Overrideprotected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);    
    setContentView(R.layout.activity_action_bar);    
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

在这里插入图片描述

setDisplayShowTitleEnabled()
  • 是否显示主副标题
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle("niuniu");getSupportActionBar().setSubtitle("niuniusub");
setDisplayShowCustomEnabled()
Button button = new Button(this);
button.setText("Button");
button.setTextSize(18);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(button);

在这里插入图片描述

注意:
  • setHomeButtonEnabled和setDisplayShowHomeEnabled共同起作用如果setHomeButtonEnabled设成false,即使setDisplayShowHomeEnabled设成true,图标也不能点击
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wjxbless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值