2

当我尝试在 2.3 中更改选项卡图标时,它可以工作但在 android 4.1.2 上没有。

 mTabHost.addTab(mTabHost.newTabSpec("device").setIndicator("Device",
                    getResources().getDrawable(R.drawable.ic_launcher)),
                    FragmentOne.class, null);

在设备 3.0 或更低版本上使用时,我可以看到 ic_launcher 图标。

4

2 回答 2

1

只是在我的选项卡中膨胀了自定义布局,这解决了我的问题 -

TabSpec tSpecWork = mTabHost.newTabSpec("work");
        View tabIndicator   = LayoutInflater.from(this).inflate(R.layout.tabimage,mTabHost.getTabWidget(),false);
        ((TextView) tabIndicator.findViewById(R.id.title_tab)).setText(getString(R.string.message)); 
        ((ImageView) tabIndicator.findViewById(R.id.icon_tab)).setImageResource(R.drawable.ic_launcher);

        tSpecWork.setIndicator(tabIndicator);    

        mTabHost.addTab(tSpecWork,
                FragmentOne.class, null);

这是我的 tabimage xml 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="0dp"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:layout_weight="1"
  android:padding="5dp" >

 <ImageView
      android:id="@+id/icon_tab"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
 />

  <TextView
      android:id="@+id/title_tab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textColor="#000000" />
</LinearLayout>
于 2013-06-07T12:56:27.937 回答