Android 选项卡图标不显示

Android 选项卡图标不显示,android,tabs,android-tabhost,android-4.0-ice-cream-sandwich,Android,Tabs,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/

我正在尝试在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>
正如你所看到的,这很简单。但是当我写
spec.setIndicator(“”)时,
res.getDrawable(android.R.drawable.ic_对话框_映射)
当我写
spec.setIndicator(“TAB2”)时,我可以看到图标bu,
res.getDrawable(android.R.drawable.ic_对话框_映射)
我只能看到TAB2,但不能同时看到它们

似乎没有足够的空间来展示两者。所以我试着用这个来增加标签的高度

tabs.getTabWidget().getChildAt(1).getLayoutParams().height = 150; 

但似乎不起作用。

//您加载的是第一个,因此只能看到最后添加的一个

 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);

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

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);

选项卡中图标(连同标签)的可见性取决于目标设备和android平台版本

我对这个问题进行了更深入的研究,并在您关于这个问题的另一个(非常类似的)问题上添加了更多细节和解决方案;可以在这里找到:


在AndroidManifest.xml中添加此选项解决了问题

<application 
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
</application>


您能再解释一下吗?我不明白你说的超载?多谢了,好的。。我们必须清除标签上的标签才能看到图标..那太糟糕了。。。顺便说一句,谢谢你的帮助,如果放置为空,我可以看到..但无法看到下面的图标文本…可以告诉我希望同时显示图标和文本。。。
<application 
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
</application>