【问题标题】:setting custom style attribute for ActionBarSherlock navigation tabs breaks default theme为 ActionBarSherlock 导航选项卡设置自定义样式属性会破坏默认主题
【发布时间】:2013-05-15 07:00:27
【问题描述】:

我正在尝试自定义 ActionBarSherlock 中的导航选项卡。如果我只是为导航选项卡设置背景,则选项卡的现有文本样式将丢失。文本缩小并在选项卡内左对齐。我的理解是我正在设置一个属性,它被合并到父主题中。它似乎完全取代了父主题。我是否必须设置所有属性才能自定义导航选项卡中的一件事?

代码如下:

/res/values/themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="MyTheme" parent="Theme.Sherlock.Light">
    <item name="android:dither">true</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarStyle</item>
    <item name="actionBarTabStyle">@style/MyActionBarStyle</item>
  </style>
  <style name="MyActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.TabBar">
    <item name="android:background">@drawable/my_new_bg</item>
  </style>
</resources>

androidmanifest.xml:

...
<application
        android:name=".MyApplication"
        android:hardwareAccelerated="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:description="@string/app_desc"
        android:theme="@style/MyTheme" >
...

【问题讨论】:

    标签: android actionbarsherlock android-theme


    【解决方案1】:

    如果您查看样式Widget.Sherlock.Light.ActionBar.TabBar 的属性,您会注意到没有与继承自相关的文本。

    <style name="Widget.Sherlock.ActionBar.TabBar" parent="Widget">
        <item name="android:divider">?attr/actionBarDivider</item>
        <item name="android:showDividers">middle</item>
        <item name="android:dividerPadding">12dip</item>
    </style>
    <style name="Widget.Sherlock.Light.ActionBar.TabBar" parent="Widget.Sherlock.ActionBar.TabBar">
    </style>
    

    也许您正在寻找actionBarTabStyleactionBarTabTextStyle

    <item name="actionBarTabStyle">@style/Widget.Sherlock.Light.ActionBar.TabView</item>
    <item name="actionBarTabTextStyle">@style/Widget.Sherlock.Light.ActionBar.TabText</item>
    

    【讨论】:

    • 啊哈!谢谢你。我将 MyActionBarStyle 重新设置为 Widget.Sherlock.Light.ActionBar.TabView 并且文本样式又回来了。我仍然不明白为什么自定义 ActionBar.TabBar 样式会影响 ActionBar.TabText 主题,但它现在可以工作了。
    【解决方案2】:

    试试这样:

      <style name="MyActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.TabBar">
        <item name="android:background">@drawable/my_new_bg</item>
        <item name="background">@drawable/my_new_bg</item>
      </style>
    

    【讨论】:

    • 同样的结果。未应用父级的文本样式。
    猜你喜欢
    • 2012-05-04
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 2013-04-23
    • 1970-01-01
    相关资源
    最近更新 更多