更改第一个标签图标

时间:2014-12-23 14:11:50

标签: android fragment-tab-host

如何更改在第一个片段中定义的标签图标,我想从第二个片段更改它?

我将标签分配给图标和标题,如下所示,我想从另一个片段中更改第一个标签图标

final TabWidget tabWidget = mTabHost.getTabWidget();
   for (int i = 0; i < tabWidget.getTabCount(); i++)
   {

        final View tab = tabWidget.getChildTabViewAt(i);

        final TextView title = (TextView) tab.findViewById(android.R.id.title);
        title.setTextSize(9);
        title.setTextColor(Color.WHITE);
        title.setGravity(Gravity.CENTER);

           if(i==0)
           {
            title.setCompoundDrawablesWithIntrinsicBounds(null, null,  null,  res.getDrawable(R.drawable.rsz_chat_blue));
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            {
               title.setText(""); // Landscape mode
            }
           }
           if(i==1)
           {
            title.setCompoundDrawablesWithIntrinsicBounds(null, null,  null,  res.getDrawable(R.drawable.rsz_contacts_blueg));
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            {
               title.setText(""); // Landscape mode
            }
           }
           if(i==2)
           {
            title.setCompoundDrawablesWithIntrinsicBounds(null, null,  null,  res.getDrawable(R.drawable.rsz_play_blue));
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            {
               title.setText(""); // Landscape mode
            }
           }
           if(i==3)
           {
            title.setCompoundDrawablesWithIntrinsicBounds(null, null,  null,  res.getDrawable(R.drawable.rsz_settings_blue));
            if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            {
               title.setText(""); // Landscape mode
            }
           }


   }

1 个答案:

答案 0 :(得分:0)

你的第二个片段中的

执行此操作:

1)从您的活动中获取tabWidgetgetActivity().getTabWiget()

2)View tab = tabWidget.getChildTabViewAt(1);

3)在选项卡中找到任何视图并进行更改

final ImageView iconView = (ImageView) tab.findViewById(android.R.id.icon); 
iconView.setImageDrawable(mIcon);