自定义动作条的TabBar(ActionBarSherlock) [英] Customize ActionBar TabBar (ActionBarSherlock)

查看:107
本文介绍了自定义动作条的TabBar(ActionBarSherlock)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直停留在这个问题上的一些日子了。谁能帮我自定义选项卡中显示下面的动作条(NavigationMode是 NAVIGATION_MODE_TABS )?

基本上,我想改变标签的背景色和当前所选选项卡的下划线颜色。到目前为止,这是我做了什么,但它不能正常工作。我使用 ActionBarSherlock

 <样式名称=Theme.Styled父=@风格/ Theme.Sherlock.Light>
    <项目名称=actionBarStyle> @风格/ Widget.Theme.Styled.ActionBar< /项目>
    <项目名称=机器人:actionBarStyle> @风格/ Widget.Theme.Styled.ActionBar< /项目>

    <项目名称=actionBarTabBarStyle> @风格/ customActionBarTabStyle< /项目>
    <项目名称=机器人:actionBarTabBarStyle> @风格/ customActionBarTabStyle< /项目>

    <项目名称=actionBarTabBarStyle> @风格/ customActionBarTabBarStyle< /项目>
    <项目名称=机器人:actionBarTabBarStyle> @风格/ customActionBarTabBarStyle< /项目>

    <项目名称=actionBarTabTextStyle> @风格/ customActionBarTabTextStyle< /项目>
    <项目名称=机器人:actionBarTabTextStyle> @风格/ customActionBarTabTextStyle< /项目>
< /风格>

<样式名称=customActionBarTabStyle父=风格/ Widget.Sherlock.Light.ActionBar.TabView>
    <项目名称=机器人:背景> @色/红色和LT; /项目>

    <项目名称=机器人:TEXTSIZE> 12dp< /项目>

< /风格>

<样式名称=customActionBarTabBarStyle父=风格/ Widget.Sherlock.Light.ActionBar.TabBar>
    <项目名称=机器人:背景> @色/红色和LT; /项目>
< /风格>

<样式名称=customActionBarTabTextStyle父=风格/ Widget.Sherlock.Light.ActionBar.TabText>
    <项目名称=机器人:titleTextStyle> @风格/ Theme.Styled.ActionBar.TitleTextStyle< /项目>
    <项目名称=机器人:TEXTSTYLE>大胆< /项目>
< /风格>

<样式名称=Widget.Theme.Styled.ActionBar父=Widget.Sherlock.ActionBar>
    <项目名称=机器人:背景>#A9E2F3< /项目>
    <项目名称=背景>#A9E2F3< /项目>
    <项目名称=机器人:titleTextStyle> @风格/ Theme.Styled.ActionBar.TitleTextStyle< /项目>
< /风格>

<样式名称=Theme.Styled.ActionBar.TitleTextStyle父=机器人:款式/ TextAppearance.Holo.Widget.ActionBar.Title>
    <项目名称=机器人:文字颜色> @色/红色和LT; /项目>
    <项目名称=机器人:TEXTSTYLE>大胆< /项目>
< /风格>

<样式名称=动画/>
 

解决方案

我不知道,如果你需要这个了,但我会发布的其他人一看便知。您可以设置此背景绘制对象 customActionBarTabStyle 为绘制资源:

 <样式名称=customActionBarTabStyle父=风格/ Widget.Sherlock.Light.ActionBar.TabView>
    <项目名称=机器人:背景> @可绘制/ actionbar_tabs_selector< /项目>
    <项目名称=机器人:TEXTSIZE> 12dp< /项目>
< /风格>
 

该资源应该是一个选择,这些线路中的内容:

 <! - 这是@绘制/ actionbar_tabs_selector布局 - &GT!;

< 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 =假机器人:可绘制=@可绘制/ actionbar_tab_style_nselected/>
    <项目安卓state_focused =假的Andr​​oid版本:state_selected =真正的机器人:STATE_ pressed =假机器人:可绘制=@可绘制/ actionbar_tab_style_selected/>

    <  - !pressed状态 - >
    <项目的android:STATE_ pressed =真正的机器人:可绘制=@可绘制/ actionbar_tab_style_selected/>

    <! - 聚焦状态 - >
    <项目安卓state_focused =真正的机器人:state_selected =假的Andr​​oid版本:STATE_ pressed =假机器人:可绘制=@可绘制/ actionbar_tab_style_nselected/>
    <项目安卓state_focused =真正的机器人:state_selected =真正的机器人:STATE_ pressed =假机器人:可绘制=@可绘制/ actionbar_tab_style_nselected/>

< /选择器>
 

因此​​,资源在这里为二层列表。一个用于当标签处于非活动状态,一当选择的选项卡和有效。所以,你设置2层列表取决于所选择的状态。

单层所列内容可能是这样的:

 <! - 这是@绘制/ actionbar_tab_style_nselected布局 - &GT!;

< XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

    <! - 底线 - >
    <项目>
        <形机器人:形状=矩形>
            [固体机器人:颜色=@色/ HCL_orange/>
        < /形状>
    < /项目>

    <! - 标签颜色 - >
    <项目安卓底=2DIP>
        <形机器人:形状=矩形>
            [固体机器人:颜色=@机器人:彩色/白/>
        < /形状>
    < /项目>
< /层列表>
 

因此​​,第一项是底线,你可以定义为当前选择的选项卡的你的下划线颜色,而第二项是整个标签的颜色

I have been stuck on this issue for some days now. Can anyone help me customize the Tabs displayed below the ActionBar (NavigationMode is NAVIGATION_MODE_TABS) ?

I basically want to change the background color of the tabs and the underline color of the currently selected Tab. So far this is what I have done, yet it doesn't work. I am using ActionBarSherlock.

<style name="Theme.Styled" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Theme.Styled.ActionBar</item>

    <item name="actionBarTabBarStyle">@style/customActionBarTabStyle</item>
    <item name="android:actionBarTabBarStyle">@style/customActionBarTabStyle</item>

    <item name="actionBarTabBarStyle">@style/customActionBarTabBarStyle</item>
    <item name="android:actionBarTabBarStyle">@style/customActionBarTabBarStyle</item>

    <item name="actionBarTabTextStyle">@style/customActionBarTabTextStyle</item>
    <item name="android:actionBarTabTextStyle">@style/customActionBarTabTextStyle</item>
</style>

<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@color/red</item>

    <item name="android:textSize">12dp</item>

</style>

<style name="customActionBarTabBarStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabBar">
    <item name="android:background">@color/red</item>
</style>

<style name="customActionBarTabTextStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabText">
    <item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="Widget.Theme.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">#A9E2F3</item>
    <item name="background">#A9E2F3</item>
    <item name="android:titleTextStyle">@style/Theme.Styled.ActionBar.TitleTextStyle</item>
</style>

<style name="Theme.Styled.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/red</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="Animations" />

解决方案

I'm not sure if you need this anymore but I will post the answer for other people to see. You can set this in the background Drawable of the customActionBarTabStyle as a Drawable resource:

<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@drawable/actionbar_tabs_selector</item>
    <item name="android:textSize">12dp</item>
</style>

The resource should be a Selector, something among these lines:

<!-- This is the "@drawable/actionbar_tabs_selector" layout !-->

<?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/actionbar_tab_style_nselected"/>
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_selected"/>

    <!-- Pressed state -->
    <item android:state_pressed="true" android:drawable="@drawable/actionbar_tab_style_selected" />

    <!-- Focused state -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/actionbar_tab_style_nselected"/>

</selector>

So the resources here are 2 Layer Lists. One for when the tab is inactive, and one for when the tab is selected and active. So you set 2 Layer Lists depending on the selected state.

A single Layer List may look like this:

<!-- This is the "@drawable/actionbar_tab_style_nselected" layout !-->

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Bottom Line -->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/HCL_orange" />
        </shape>
    </item>

    <!-- Tab color -->
    <item android:bottom="2dip">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
        </shape>
    </item>
</layer-list>

Thus the first item is the bottom line that you could define as your underline color of the currently selected Tab, and the second item is the color of the whole tab.

这篇关于自定义动作条的TabBar(ActionBarSherlock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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