我已将ActionBar选项卡添加到我的应用程序中。该下划线的默认颜色为浅蓝色。如何更改所选选项卡的颜色或样式?
如果有人想在代码中更改操作栏的颜色/背景,可以像这样做
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar_bg));
更改在Actionbar下方的选项卡栏颜色:
actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.color_brown_dark)));
更改选项卡栏的背景:
actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
R.drawable.coupon_header));
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
,这将更改操作栏上的高亮颜色。像这样:
<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选项卡下划线颜色不改变
1) 生成操作栏样式,点击下载ZIP文件获取文件。
2) 解压步骤1中创建的zip文件后,您将获得一个res文件夹。将此文件夹添加到您的项目下的platform/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>
这篇手册帮助了我,希望对你也有所帮助。