【发布时间】: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有问题吗?而且我认为您的选择器中应该有以下组合:<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_bar_background_selected"/>
标签: android styles android-actionbar themes actionbarsherlock