造型的TabBar指示剂与ActionBarSherlock [英] Styling tabBar-indicator with ActionBarSherlock

查看:198
本文介绍了造型的TabBar指示剂与ActionBarSherlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前无法使用Actionbarsherlock时,在我的应用程序自定义选项卡指示器。我试图更改默认的颜色(蓝色),以白色的指示灯。所有其他定制按预期工作。我甚至无法删除制表指标。我错过了一些东西在我的XML的code或可能是什么问题?另外请注意,我最小的SDK设置为14,在清单-file。所有帮助是必要的,所以我可以设法找到了问题的根源:/问候

Tabs.java

  @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.tab_host);

动作条动作条= getSupportActionBar();
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            actionBar.setDisplayShowTitleEnabled(真正的);
            actionBar.setDisplayShowHomeEnabled(真正的);
            actionBar.setTitle(R.string.LabelTitleAbout);


            actionBar.addTab(actionBar.newTab()。
                setTabListener(新TabListener< LandingSearch>(这一点,的getString(R.string.LabelSearchTabTitle),LandingSearch.class,NULL)));

在code继续与构造等...
 

tab_host.xml

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直
    >

    <的LinearLayout
        机器人:ID =@ + ID / tabs_navigation_content
        机器人:方向=垂直
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>
    < / LinearLayout中>
< / LinearLayout中>
 

值/的themes.xml

 <样式名称=Theme.ML父=@风格/ Theme.Sherlock>
    <项目名称=windowNoTitle>真< /项目>
    <项目名称=机器人:actionBarTabBarStyle> @风格/ Theme.ML.Tabs< /项目>
     <项目名称=actionBarTabBarStyle> @风格/ Theme.ML.Tabs< /项目>
< /风格>

<样式名称=Theme.ML.Tabs父=Widget.Sherlock.Light.ActionBar.Solid.Inverse>
    <项目名称=windowNoTitle>真< /项目>
    <项目名称=背景> @可绘制/ tab_bar_background< /项目>
    <项目名称=机器人:背景> @可绘制/ tab_bar_background< /项目>

< /风格>
...
 

绘制/ tab_bar_background.xml

 < XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
  <项目安卓state_focused =假的Andr​​oid版本:state_selected =假的Andr​​oid版本:STATE_ pressed =假机器人:可绘制=@可绘制/ menu_blank_off/>
  <项目安卓state_focused =假的Andr​​oid版本:state_selected =真正的机器人:STATE_ pressed =假机器人:可绘制=@可绘制/ tab_bar_background_selected/>
  <项目安卓state_selected =假的Andr​​oid版本:STATE_ pressed =真正的机器人:可绘制=@色/白/>
  <项目安卓state_selected =真正的机器人:STATE_ pressed =真正的机器人:可绘制=@可绘制/ tab_bar_background_selected_ pressed/>
< /选择器>
 

tab_bar_background_selected.xml

 < XML版本=1.0编码=UTF-8&GT?;

<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目的android:顶部= -  5DP机器人:左= -  5DP机器人:右= -  5DP>
        <形机器人:形状=矩形>
            <行程机器人:颜色=#FFFFFF机器人:宽=5DP/>

        < /形状>
    < /项目>
< /层列表>
 

解决方案

由于维克拉姆说你已经使用 API 14 + 为什么要使用 ActionBarSherlock 在默认的操作栏,

一个可以自定义动作条使用 Android的动作栏样式生成器不同变化。

为什么ABS标签指标不变化?

正如你说你的动作栏选项卡指示器颜色不会得到改变,这是为什么 人们不必到样式属性,它应该属于。

 <样式名称=Theme.ML.Tabs父=Widget.Sherlock.Light.ActionBar.Solid.Inverse>
 

不正确的地方风格你操作栏标签

解决方案: -

 <样式名称=Theme.ML父=@风格/ Theme.Sherlock>
    <项目名称=windowNoTitle>真< /项目>
    <项目名称=机器人:actionBarTabStyle> @风格/ Theme.ML.Tabs< /项目>
    <项目名称=actionBarTabBarStyle> @风格/ Theme.ML.Tabs< /项目>
< /风格>

<样式名称=Theme.ML.Tabs父=@风格/ Widget.Sherlock.Light.ActionBar.TabView>
        <项目名称=机器人:背景> @可绘制/ tab_bar_background< /项目>
< /风格>
 

I am currently not able to customize the tab-indicator in my app when using Actionbarsherlock. I am trying to change the default color (blue) to white of the indicator. All other customization works as intended. I am not even able to remove the tab-indicator. Have I missed something in my XML-code or what might be the problem? Also note, my min-SDK is set to 14 in the manifest -file. ALL help is needed so I can manage to find the source of the problem :/ Regards

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>

解决方案

As Vikram said you already using API 14+ why to use ActionBarSherlock over default action bar,

One can customise ActionBar with different variation using Android Action Bar Style Generator.

Why ABS Tab indicator not changing?

As you said your action bar tab indicator color is not get changed, here is why one need to styling attributes where it should belongs to.

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

is not right place to style your Action Bar Tabs.

Solution:-

<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>

这篇关于造型的TabBar指示剂与ActionBarSherlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆