2012-06-09 5 views
8

私は2つのタブでアンドロイドで簡単なタブアプリをやろうとしています。私の問題は、このコードをタブに置くと、テキストのみが表示され、アイコンは表示されないということです。 ""にテキストを置くとアイコンが表示されます。タブアイコンが表示されない

誰かが私を助けることができますか?私のアンドロイド版は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

は//あなたが見ることができるので、第一1をロードの上にアールは、最後は私がNULL値でラベル名を置き換え

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

もう少し説明できますか?私はあなたが過負荷と言うとき理解していない?おかげでたくさん – theholy

+0

これは私のために働いていません –

8

1を追加しました。 アイコンだけが表示されます。 他の解決策は見つかりませんでした。

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

ウル右..私たちはアイコンのラベルをクリアする必要があります.thatsたわごと... ところであなたのおかげで助けてくれる友だち – Noman

+0

場所ヌル私は見ることができます..しかし、下のアイコンのテキストを見ることができません...私はアイコンとテキストを表示したいと言うことができます... –

2

タブで(一緒にラベルが付いた)アイコンの視認性は、ターゲットデバイスとAndroidプラットフォームのバージョンに依存します。

私はこの問題について詳しく調べて、この問題についてのあなたの他の(かなりシンプリアな)質問にもっと詳細と解決策を追加しました。それは、ここで見つけることができます:

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

0

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

<application 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@android:style/Theme.NoTitleBar"> 
</application> 
関連する問題