我现在尝试了几个小时来覆盖自定义选项卡样式的 AppCombat 主题,但我的更改没有任何效果。这是我的 style.xml
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="actionBarTabStyle">@style/MyActionBarTabs.AppTheme</item>
</style>
<!-- ActionBar tabs styles -->
<style name="MyActionBarTabs.AppTheme" parent="@style/Widget.AppCompat.ActionBar.TabView">
<item name="background">@drawable/tab_bar_background</item>
</style>
我使用 android-support-libray-v7 在旧版 Android 中使用 ActionBarTabStyle
。这是 tab_bar_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/boni_red" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/boni_red" />
<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/boni_red" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/boni_red" />
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="true"
android:drawable="@color/boni_red" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="true"
android:drawable="@color/boni_red" />
<!-- Focused states (such as when focused with a d-pad or mouse hover) -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="true"
android:drawable="@color/boni_red" />
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="true"
android:drawable="@color/boni_red" />
在 TabActivity
类中,我只是使用 TabHost
添加了一些选项卡,此 Activity 的布局如下所示:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/TabBarLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/header_logo"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@color/boni_red"
android:text="@string/app_name_capital"
android:textStyle="bold"
android:gravity="center"
android:textSize="25sp"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
</TabWidget>
</LinearLayout>
我刚刚按照 android developer page 提供的教程进行操作. 我的应用程序中的标签栏看起来像图片中的浅色标签栏。
为什么我的风格没有覆盖标准风格有什么建议吗?其实一切都应该是红色的!我做错了什么吗? 谢谢并致以最诚挚的问候, 最大
最佳答案
将以下内容添加到:values-v11(不要忽略“android:”)
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarTabStyle">@style/MyActionBarTabs.AppTheme</item>
修改styles.xml中的以下内容(不要忽略‘android:’)
<item name="android:background">@drawable/tab_bar_background</item>
`
关于android - 自定义 'actionBarTabStyle' 不会覆盖 AppCompat 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21936008/