【问题标题】:How to change the background of the tabhost如何更改tabhost的背景
【发布时间】:2014-01-19 02:47:37
【问题描述】:

我有一个带有 ~ 5 个标签的标签主机,我想更改它的背景。有一个标签的背景图像,一个所有标签的矩形图像。当我添加到 tabhost 。这是行不通的。如何解决?谢谢

   <android.support.v4.app.FragmentTabHost
        android:id="@+id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal"
        android:background="@drawable/tabBg"
   /> 

【问题讨论】:

    标签: android android-layout android-tabhost android-tabs


    【解决方案1】:

    这样做...

    tabhost
     .getTabWidget()
     .getChildAt(/*Index of the tab of which you want to change the background*/)
     .setBackground(/*the background res you want to set */)
    

    【讨论】:

      【解决方案2】:

      试试这个

      spec = tabHost.newTabSpec("orders")
             .setIndicator("Orders",res.getDrawable(R.drawable.flash_36))
             .setContent(R.id.ordersLayout);
      

      【讨论】:

        【解决方案3】:

        终于解决了

        public void setTabColor(TabHost tabhost) {
                for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
                {
                     tabhost.getTabWidget().getChildAt(i).setBackground(res.getDrawable(R.drawable.share_tab_bg)); // selected
                }
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-08-24
          • 1970-01-01
          相关资源
          最近更新 更多