8

私は2つのタブを備えた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>

アクティビティコードは

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

ご覧のとおり、非常に簡単です。しかし、私が書くとき、私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; 

しかし、うまくいかないようです。

4

4 に答える 4

8

ラベル名をnull値に置き換えました。今、私はアイコンだけを見ることができます..他の解決策を見つけることができませんでした。

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);
于 2012-06-29T10:48:39.613 に答える
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);
于 2012-06-09T20:37:11.340 に答える
2

タブ内のアイコンの表示(ラベルと一緒に)は、ターゲットデバイスとAndroidプラットフォームのバージョンによって異なります。

私はこの問題をより深く調査し、この問題に関する他の(非常に類似した)質問に詳細と解決策を追加しました。それはここで見つけることができます:

https://stackoverflow.com/a/11379708/414581

于 2012-07-08T00:21:54.770 に答える
1

これをAndroidManifest.xmlに追加すると、問題が解決しました。

<application 
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
</application>
于 2014-07-08T18:00:10.177 に答える