【问题标题】:Android TabHost change color of the bottom barAndroid TabHost改变底栏的颜色
【发布时间】:2013-06-21 11:03:15
【问题描述】:

现在已经搜索了一段时间并且努力让任何工作。

我需要将蓝色底栏的颜色更改为十六进制值,我已经更改了选项卡的背景颜色,但它没有更改 TanHost 上的蓝色。是否有可能真正改变这一点?我看到 youtube 把它变成了一个漂亮的红色,所以它一定是可行的!这是设置tabhost:

标签是由它们自己的类控制的片段

// set up the tabhost
         mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
            mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
            mTabHost.addTab(mTabHost.newTabSpec("event").setIndicator("Event Locations",
                    getResources().getDrawable(R.drawable.ic_event_tab)),
                    EventFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("itin").setIndicator("Itinerary",
                    getResources().getDrawable(R.drawable.ic_itin_tab)),
                       ItineraryFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("info").setIndicator("Kendal Info",
                    getResources().getDrawable(R.drawable.ic_info_tab)),
                    KendalInfoFragment.class, null);

            mTabHost.getTabWidget().setBackgroundColor(Color.RED);

【问题讨论】:

    标签: java android


    【解决方案1】:

    假设已弃用的库照常工作,这就是我用来为标签着色的过程。我只是在代码中设置了背景,因为它不能在 xml 中直接访问:

     TabWidget tabs = (TabWidget)getTabWidget();            
            for (int i = 0; i<tabs.getChildCount(); i++) {
                RelativeLayout tab = (RelativeLayout) tabs.getChildAt(i);
                tab.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.tabindicator));
    

    tabindicator drawable如下:

    <?xml version="1.0" encoding="utf-8" ?> 
    <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" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" /> 
    <!--  Focused states  --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" /> 
     <!--  Pressed  --> 
    <item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_press" /> 
    <item android:state_pressed="true" android:drawable="@drawable/tab_press" /> 
    </selector>
    

    drawables 只是带有颜色的 9-patch 图像,尽管您可以使用标准颜色获得类似的效果。

    Links1 Link2

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多