试图改变标签指示灯颜色 [英] Trying to change tab indicator color

查看:183
本文介绍了试图改变标签指示灯颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经生成自定义操作栏<一个href=\"http://jgilfelt.github.io/android-actionbarstylegenerator/#name=example&compat=holo&theme=light&actionbarstyle=solid&texture=0&hairline=0&backColor=E4E4E4,100&secondaryColor=D6D6D6,100&tabColor=33B5E5,100&tertiaryColor=F2F2F2,100&accentColor=33B5E5,100&cabBackColor=FFFFFF,100&cabHighlightColor=33B5E5,100\"相对=nofollow>这里和一切正常,除了标签。选项​​卡指示器和制表背景颜色保持不变,不管是什么。

I've generated a custom action bar here and everything works except for tabs. Tab indicator and tab background color stays the same no matter what.

tab_indicator_ab_recorder.xml文件:

tab_indicator_ab_recorder.xml file:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_recorder" />
<item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_recorder" />

<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_recorder" />
<item android:state_focused="true" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_recorder" />

<!-- Pressed -->
<!--    Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_recorder" />
<item android:state_focused="false" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_recorder" />

<!--    Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_recorder" />
<item android:state_focused="true" android:state_selected="true"  android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_recorder" />

Accourding的文档,我需要这个xml文件来覆盖标签布局的背景属性。但我怎么办呢?我试着这样做:

Accourding to documentation, I need to override background attribute of tab layout with this xml file. But how do I do it? I tried doing this:

<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/tab_indicator_ab_recorder"/>

但是这是行不通的。任何想法,我怎么能解决这个问题?

but this isn't working. Any idea how could I fix this?

推荐答案

您可以指定你的java code选项卡指示器。下面是我设置的标签主机时一样。添加完成code两个选项卡澄清。该getTabIndicator()方法是相关的部分,但。

You could specify the tab indicator in your java code. Below is what I did when setting up the tab host. Added complete code with two tabs for clarification. The getTabIndicator() method is the relevant part though.

private void initTabs(String currentTab) {
    mTabHost = (TabHost) mRootView.findViewById(R.id.orderTabHost);
    mTabHost.setup();

    // Add drawing tab
    TabHost.TabSpec drawingTab = mTabHost.newTabSpec(DRAWING_TAB_TAG);
    drawingTab.setContent(R.id.tab_drawing_container);
    String drawingTitle = getResources().getString(R.string.drawing_title);
    drawingTab.setIndicator(getTabIndicator(drawingTitle));
    mTabHost.addTab(drawingTab);

    // Add detail tab
    TabHost.TabSpec detailTab = mTabHost.newTabSpec(DETAIL_TAB_TAG);
    detailTab.setContent(R.id.tab_info_container);
    String detailTitle = getResources().getString(R.string.detail_title);
    detailTab.setIndicator(getTabIndicator(detailTitle));
    mTabHost.addTab(detailTab);
}

// Call this for every tab.
private View getTabIndicator(String tabTitle) {
    View tabIndicator = LayoutInflater.from(getActivity()).inflate(
            R.layout.tab_indicator_holo, mTabHost.getTabWidget(), false);
    TextView title = (TextView) tabIndicator
            .findViewById(android.R.id.title);
    title.setText(tabTitle);
    return tabIndicator;
}

这篇关于试图改变标签指示灯颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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