android - 自定义 'actionBarTabStyle' 不会覆盖 AppCompat 主题

标签 android android-actionbar android-tabs android-appcompat

我现在尝试了几个小时来覆盖自定义选项卡样式的 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 提供的教程进行操作. 我的应用程序中的标签栏看起来像图片中的浅色标签栏。 TabBar

为什么我的风格没有覆盖标准风格有什么建议吗?其实一切都应该是红色的!我做错了什么吗? 谢谢并致以最诚挚的问候, 最大

最佳答案

将以下内容添加到: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/

相关文章:

android - 将焦点添加到微调器

android - 为 Android Actionbar Button 动态更改文本

Android:WebView ActionBar( hive )?

android - 如何以编程方式滚动 tablayout - Android

android - 在上下文操作栏中,如何通过使选项卡不可点击/滑动来禁用滑动选项卡?

android - 应用程序意外停止,

java - 如何打包我的 Android ReSTLet 服务器所需的静态文件?

android - Volley POST 请求,400 错误

android - 获取ARGB_8888 Android Bitmap中的原始数据

Android ActionBar.Tab setCustomView() 不 fill_parent