选项卡图标未显示

the*_*oly 8 tabs android android-tabhost android-4.0-ice-cream-sandwich

我正在尝试用两个标签在android中做一个简单的标签应用程序.我的问题是,当我把这个代码放在选项卡中时,只显示文本,但没有显示图标.如果我将文本放到"",则显示图标.

有人能帮助我吗?我的Android版本是4.0.3.

非常感谢.

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/tabhost"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" >
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

     <TabWidget android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@android:id/tabs" />

     <FrameLayout android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@android:id/tabcontent" >

        <LinearLayout android:id="@+id/tab1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <TextView android:id="@+id/textView1"
                android:text="Contenido Tab 1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    </LinearLayout>

        <LinearLayout android:id="@+id/tab2"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <TextView android:id="@+id/textView2"
                android:text="Contenido Tab 2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    </LinearLayout>

     </FrameLayout>
</LinearLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)

而活动代码是

public class TabTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Resources res = getResources();

    TabHost tabs=(TabHost)findViewById(R.id.tabhost);
    tabs.setup();

    TabHost.TabSpec spec=tabs.newTabSpec("mitab1");
    spec.setContent(R.id.tab1);
    spec.setIndicator("sss",
            res.getDrawable(android.R.drawable.ic_btn_speak_now));
    tabs.addTab(spec);

    spec=tabs.newTabSpec("mitab2");
    spec.setContent(R.id.tab2);
    spec.setIndicator("TAB2",
            res.getDrawable(android.R.drawable.ic_dialog_map));
    tabs.addTab(spec);



    tabs.setCurrentTab(0);
}
Run Code Online (Sandbox Code Playgroud)

你可以看到非常简单.但是当我写作时,spec.setIndicator("", res.getDrawable(android.R.drawable.ic_dialog_map)); 我可以看到图标,当我写作时,spec.setIndicator("TAB2", res.getDrawable(android.R.drawable.ic_dialog_map)); 我只能看到TAB2,但不能同时看到它们.

似乎没有任何可以展示的空间.所以我试图用这个增加标签高度

tabs.getTabWidget().getChildAt(1).getLayoutParams().height = 150; 
Run Code Online (Sandbox Code Playgroud)

但似乎不起作用.

ars*_*had 8

我用空值替换了标签名称.现在我可以单独看到图标..无法找到任何其他解决方案.

TabHost.TabSpec spec=tabs.newTabSpec("mitab1");

spec.setIndicator("",
                  res.getDrawable(android.R.drawable.ic_btn_speak_now));
Intent sssIntent = new Intent(this, First.class);
spec.setContent(sssIntent);
tabs.addTab(spec);
Run Code Online (Sandbox Code Playgroud)


Pad*_*mar 4

//你超载了第一个,所以你只能看到最后添加的一个

 TabHost.TabSpec spec=tabs.newTabSpec("mitab1");

        spec.setIndicator("sss",
                res.getDrawable(android.R.drawable.ic_btn_speak_now));
 Intent sssIntent = new Intent(this, First.class);
 spec.setContent(sssIntent);
        tabs.addTab(spec);

TabHost.TabSpec spec2=tabs.newTabSpec("mitab2");
        spec2=tabs.newTabSpec("mitab2");
        spec2.setIndicator("TAB2",
                res.getDrawable(android.R.drawable.ic_dialog_map));
Intent sssIntent2 = new Intent(this, Second.class);
 spec2.setContent(sssIntent2 );
        tabs.addTab(spec2);
Run Code Online (Sandbox Code Playgroud)