【发布时间】:2011-09-28 14:40:09
【问题描述】:
我已将 ActionBar 选项卡添加到我的应用程序中。该下划线的默认颜色是浅蓝色。如何更改所选标签的颜色或样式?
【问题讨论】:
标签: android
我已将 ActionBar 选项卡添加到我的应用程序中。该下划线的默认颜色是浅蓝色。如何更改所选标签的颜色或样式?
【问题讨论】:
标签: android
如果有人想在代码中更改操作栏颜色/背景,您可以这样做
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar_bg));
更改操作栏下的标签栏颜色:
actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.color_brown_dark)));
改变标签栏背景:
actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
R.drawable.coupon_header));
【讨论】:
这可能会提供一些线索Action Bar Style Gen
【讨论】:
selectableItemBackground 是我认为您正在寻找的属性。
我建议你阅读这篇关于Customizing the Action Bar 的文章,以及查看this question on SO 和this one。
在代码中,我似乎无法找到自定义所选单个项目的方法,但是自定义栏本身看起来像这样。
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("FF0000"));
【讨论】:
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// set background for action bar
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0c2354")));
// set background for action bar tab
bar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0")));
bar.show();
【讨论】:
这是一个更简单的方法:
我已经为此苦苦挣扎了好几天,但终于找到了解决方案。我正在使用 AppCompat。您可以在您的主题中设置colorAccent,这将改变您的ActionBar 上的突出显示颜色。像这样:
<item name="colorAccent">@color/highlightcolor</item>
这里是上下文:
<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/darkgrey</item>
<item name="colorPrimaryDark">@color/black</item>
<item name="colorAccent">@color/highlightcolor</item>
</style>
我最初发布此答案的位置:Android Tab underline color not changing
【讨论】:
1)Generate the Action Bar Style,点击下载ZIP获取文件
2) 当您解压在步骤 1 中创建的 zip 文件时,您将获得一个 res 文件夹。将此文件夹添加到您的项目中的平台/android 下。
3) 修改 manifest.xml 以使用新的操作栏样式,其中“Action”是您在步骤 1 中设置的样式的名称。
<android xmlns:android="http://schemas.android.com/apk/res/android">
<tool-api-level>14</tool-api-level>
<manifest>
<application android:theme="@style/Theme.Action"/>
<uses-sdk android:minSdkVersion="14"
android:targetSdkVersion="16"/>
</manifest>
</android>
This手册帮助了我,我希望它也能帮助你。
【讨论】: