不可能改变制表符ActionBarSherlock的背景 [英] Impossible to change the background of tabs with ActionBarSherlock

查看:127
本文介绍了不可能改变制表符ActionBarSherlock的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变标签的背景。我什么都试过在过去2天,所以我决定后我的code在这里。在动作条的背景设置正确,但TABS保持为黑色。

 <样式名称=CustomActivityTheme父=Theme.Sherlock>
    <项目名称=机器人:actionBarStyle> @风格/ MyActionBar< /项目>
    <项目名称=机器人:actionBarTabStyle> @风格/ MyActionBarTabStyle< /项目>
    <! - 其他活动和行动酒吧风格在这里 - >
< /风格>

<! - 风格的动作栏背景 - >
<样式名称=MyActionBar父=Widget.Sherlock.ActionBar>
    <项目名称=机器人:背景> @可绘制/ backgroundactionbar< /项目>
< /风格>


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

在清单:

 <活动机器人:名称=。FragmentActivityDashboard
              机器人:标签=@字符串/ APP_NAME
              机器人:configChanges =keyboardHidden |方向|屏幕布置
              机器人:主题=@风格/ CustomActivityTheme
              >
    < /活性GT;
 

解决方案

您需要声明两件事情改变。机器人:actionBarStyle和actionBarStyle

 <! - 主题标签和动作条背景 - >
<样式名称=Theme.Tabs父=Theme.Sherlock>
    <项目名称=机器人:actionBarTabStyle> @风格/ ActionBarTab< /项目>
    <项目名称=actionBarTabStyle> @风格/ ActionBarTab< /项目>

    <项目名称=机器人:actionBarStyle> @风格/ ActionBarBlank< /项目>
    <项目名称=actionBarStyle> @风格/ ActionBarBlank< /项目>
< /风格>

<! - 样式对于上述主题 - >
<样式名称=ActionBarBlank父=Widget.Sherlock.ActionBar>
    <项目名称=机器人:背景> @可绘制/ tab_bg< /项目>
    <项目名称=背景> @可绘制/ tab_bg< /项目>
< /风格>

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

请注意,该绘制的标签在XML文件中声明,以表明对选定的选项卡中的单独绘制。

这里的bg_tab:

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

<! - 选择 - >
<项目安卓state_selected =真正的机器人:可绘制=@可绘制/ tab_bg/>

<! - 正常 - >
<项目机器人:可绘制=@可绘制/透明/>

< /选择器>
 

I would like to change the background of the tabs. I tried everything during the last 2 days, so I decided to post my code here. The background of the ActionBar is set correctly but the TABS stay black.

  <style name="CustomActivityTheme" parent="Theme.Sherlock">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
    <!-- other activity and action bar styles here -->
</style>

<!-- style for the action bar backgrounds -->
<style name="MyActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">@drawable/backgroundactionbar</item>
</style>


<style name="MyActionBarTabStyle" parent="Widget.Sherlock.ActionBar.TabView">
<item name="android:background">@drawable/backgroundactionbar</item>
</style>

On the manifest:

         <activity android:name=".FragmentActivityDashboard"
              android:label="@string/app_name"
              android:configChanges="keyboardHidden|orientation|screenLayout"
              android:theme="@style/CustomActivityTheme"
              > 
    </activity>

解决方案

You need to declare two things to change. android:actionBarStyle and actionBarStyle

<!-- Theme For Tabs and ActionBar Background -->
<style name="Theme.Tabs" parent="Theme.Sherlock">
    <item name="android:actionBarTabStyle">@style/ActionBarTab</item>
    <item name="actionBarTabStyle">@style/ActionBarTab</item>

    <item name="android:actionBarStyle">@style/ActionBarBlank</item>
    <item name="actionBarStyle">@style/ActionBarBlank</item>
</style>

<!-- Styles for the above theme -->
<style name="ActionBarBlank" parent="Widget.Sherlock.ActionBar">
    <item name="android:background">@drawable/tab_bg</item>
    <item name="background">@drawable/tab_bg</item>
</style>

<style name="ActionBarTab" parent="Widget.Sherlock.ActionBar.TabView">
    <item name="android:background">@drawable/bg_tab</item>
    <item name="background">@drawable/bg_tab</item>
</style>

Note that the drawable for tabs are declared in xml file, to indicate the separate drawable for selected tab.

Here's the bg_tab:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Selected -->
<item android:state_selected="true" android:drawable="@drawable/tab_bg" />

<!-- Normal -->
<item android:drawable="@drawable/transparent" />

</selector>

这篇关于不可能改变制表符ActionBarSherlock的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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