【问题标题】:Styling tabBar-indicator with ActionBarSherlock使用 ActionBarSherlock 设置 tabBar-indicator 样式
【发布时间】:2023-03-30 16:08:01
【问题描述】:

当使用 Actionbarsherlock 时,我目前无法在我的应用程序中自定义选项卡指示器。我正在尝试将指示器的默认颜色(蓝色)更改为白色。所有其他自定义都按预期工作。我什至无法删除标签指示器。我是否遗漏了我的 XML 代码中的某些内容或可能是什么问题?另请注意,我的 min-SDK 在 manifest -file 中设置为 14。需要所有帮助,这样我才能找到问题的根源:/问候

Tabs.java

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_host);

ActionBar actionBar = getSupportActionBar();
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setTitle(R.string.LabelTitleAbout);


            actionBar.addTab(actionBar.newTab().
                setTabListener(new TabListener<LandingSearch>(this, getString(R.string.LabelSearchTabTitle), LandingSearch.class, null)));

the code continues with the constructor etc...

tab_host.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <LinearLayout
        android:id="@+id/tabs_navigation_content"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </LinearLayout>
</LinearLayout>

values/themes.xml

<style name="Theme.ML" parent="@style/Theme.Sherlock">
    <item name="windowNoTitle">true</item>
    <item name="android:actionBarTabBarStyle">@style/Theme.ML.Tabs</item>
     <item name="actionBarTabBarStyle">@style/Theme.ML.Tabs</item>
</style>

<style name="Theme.ML.Tabs" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="windowNoTitle">true</item>
    <item name="background">@drawable/tab_bar_background</item> 
    <item name="android:background">@drawable/tab_bar_background</item>

</style>
...

drawable/tab_bar_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/menu_blank_off"/>
  <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_bar_background_selected"/>
  <item android:state_selected="false" android:state_pressed="true" android:drawable="@color/white"/>
  <item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_bar_background_selected_pressed"/>
</selector>

tab_bar_background_selected.xml

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="-5dp" android:left="-5dp" android:right="-5dp">
        <shape android:shape="rectangle">
            <stroke android:color="#ffffff" android:width="5dp"/>

        </shape>
    </item>
</layer-list>

【问题讨论】:

  • 当你的 minSdkVersion 设置为 14 时,我可以知道你为什么使用 ABS 吗?股票ActionBar 有问题吗?而且我认为您的选择器中应该有以下组合:&lt;item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_bar_background_selected"/&gt;

标签: android styles android-actionbar themes actionbarsherlock


【解决方案1】:

正如 Vikram 所说,您已经在使用 API 14+ 为什么要在默认操作栏上使用 ActionBarSherlock

可以使用Android Action Bar Style Generator 自定义具有不同变化的ActionBar。

为什么 ABS Tab 指示器没有变化?

正如您所说,您的操作栏选项卡指示器颜色没有改变,这就是原因 需要为它应该属于的属性设置样式。

<style name="Theme.ML.Tabs" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">

不是为您的Action Bar Tabs 设置样式的正确位置。

解决方案:-

<style name="Theme.ML" parent="@style/Theme.Sherlock">
    <item name="windowNoTitle">true</item>
    <item name="android:actionBarTabStyle">@style/Theme.ML.Tabs</item>
    <item name="actionBarTabBarStyle">@style/Theme.ML.Tabs</item>
</style>

<style name="Theme.ML.Tabs" parent="@style/Widget.Sherlock.Light.ActionBar.TabView">
        <item name="android:background">@drawable/tab_bar_background</item>
</style>

【讨论】:

    【解决方案2】:

    您可以使用操作栏样式生成器完全自定义操作栏样式,此处是操作栏样式生成器的链接: Action Bar Style Generator

    你也可以从这个例子中做:-Customize Action bar

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 1970-01-01
      • 2012-08-12
      • 2013-05-04
      • 2012-04-09
      • 1970-01-01
      • 2014-07-22
      • 1970-01-01
      • 2014-02-10
      相关资源
      最近更新 更多