我试图找到一种方法来以编程方式操纵Android ActionBar及其标签的外观,但在使用API时这个过程并不简单。我想更改ActionBar的背景颜色和字体,但我也想让它与各个标签的背景颜色和字体相匹配。有没有一种简单的方法可以在代码中或使用样式?
答案 0 :(得分:0)
这组样式格式化操作栏,包括背景,标题和副标题文本;它还格式化选项卡,包括所有状态(选定,未选中和所有聚焦/按下的组合),以及选项卡文本字体和大小(根据Android开发人员指令https://developer.android.com/training/basics/actionbar/styling.html):
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/themeActionBar</item>
<item name="android:actionBarTabTextStyle">@style/styleActionBarTabText</item>
<item name="android:actionMenuTextColor">@color/actionbar_text</item>
<item name="android:actionBarTabStyle">@style/styleActionBarTabs</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/themeActionBar</item>
<item name="actionBarTabTextStyle">@style/styleActionBarTabText</item>
<item name="actionMenuTextColor">@color/actionbar_text</item>
<item name="actionBarTabStyle">@style/styleActionBarTabs</item>
</style>
<!-- ActionBar styles -->
<style name="themeActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/abactionbargradient</item>
<item name="android:titleTextStyle">@style/styleActionBarTitleText</item>
<item name="android:subtitleTextStyle">@style/styleActionBarSubTitleText</item>
<!-- Support library compatibility -->
<item name="background">@drawable/abactionbargradient</item>
<item name="titleTextStyle">@style/styleActionBarTitleText</item>
<item name="subtitleTextStyle">@style/styleActionBarSubTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="styleActionBarTitleText"
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_title_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar title text -->
<style name="styleActionBarSubTitleText"
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle">
<item name="android:textColor">@color/actionbar_sub_title_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar tabs text -->
<style name="styleActionBarTabText"
parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/actionbar_text</item>
<item name="android:textSize">10dp</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar tabs styles -->
<style name="styleActionBarTabs"
parent="@style/Widget.AppCompat.ActionBar.TabView">
<!-- tab indicator -->
<item name="android:background">@drawable/abactionbartabs</item>
<!-- Support library compatibility -->
<item name="background">@drawable/abactionbartabs</item>
</style>
当drawables是使用一些连贯的颜色值的渐变时(即未选择的薰衣草到紫色,未选择的紫色到薰衣草,将值更改为更暗的按压和更轻的焦点),这组样式看起来特别好。< / p>