[英]Custom background for an ActionBar Item
I would like to set a custom background/drwable for my action bar item. 我想为我的操作栏项设置自定义背景/可拖动背景。 Ideally to have the "Save job" thing as a "white text over dark blue" button.
理想情况下,将“保存作业”设置为“深蓝色的白色文本”按钮。
Any hint ? 有什么提示吗?
Basic editting of action bar items straight from: http://developer.android.com/training/basics/actionbar/adding-buttons.html 直接从以下位置进行操作栏项目的基本编辑: http : //developer.android.com/training/basics/actionbar/adding-buttons.html
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/SAVE_JOB" //Save job button
android:textColorolor="Your hex color" //Whatever color you want
android:background="@drawable/yourbackground" //Whatever picture you want
android:showAsAction="always" />
The yourbackground
will be located in your drawable folder, and your hex color will be in the fashion #FFFFFF
. yourbackground
将位于您的drawable文件夹中,并且您的十六进制颜色将采用#FFFFFF
的形式。
ActionBar actionBar = getSupportActionBar();
View actionBarView = getLayoutInflater().inflate(
R.layout.custom_bar, null);
actionBar.setCustomView(actionBarView);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setDisplayShowCustomEnabled(true);
Set your custom actionbarview and do whatever you want in xml. 设置您的自定义actionbarview并在xml中执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.