gpt4 book ai didi

android - 如何设置 ActionBar 的样式,选定选项卡上的选项卡背景

转载 作者:IT老高 更新时间:2023-10-28 23:24:12 26 4
gpt4 key购买 nike

我正在努力设计 ActionBar 的样式。我的应用程序有一个带有三个选项卡的 ActionBar。我试图让选定的选项卡具有背景颜色,而未选定的选项卡显示不同的颜色。我正在关注这个引用:Customizing Action Bar .但是所有的 TAB 都显示为 Selected 颜色。

我的styles.xml文件如下:

<style name="MyActionBarTabStyle" parent="android:style/Widget.Holo.Light.ActionBar.TabBar">
<item name="android:background">@drawable/tab_background</item>
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>

<style name="MyActionBarTabBarStyle" parent="android:style/Widget.Holo.Light.ActionBar.TabBar">

<item name="android:background">@drawable/red</item>
</style>


<style name="AppTheme.Light" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar.Light</item>
<item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
<item name="android:actionBarTabBarStyle">@style/MyActionBarTabBarStyle</item>

</style>

tab_background 只是一个 9 补丁。我也不确定我是否从正确的父级 (parent="android:style/Widget.Holo.Light.ActionBar.TabBar) 继承了操作栏选项卡。我已经看过了引用并发现很难理解样式层次结构

为什么我的标签不显示选中或不显示?提前感谢您的帮助。

最佳答案

我解决了我的问题。我最初没有使用 State List Drawables。我直接使用了背景图像,而不是通过 StateListDrawable。使用StateListDrawable,可以根据标签是否被选中设置不同的背景。

所以我添加了文件tab_background_select.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@drawable/tab_background" />

</selector>

我从我的 styles.xml 中引用了这个:

 <item name="android:background">@drawable/tab_background_select</item>

关于android - 如何设置 ActionBar 的样式,选定选项卡上的选项卡背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13285490/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com