2013-06-13 8 views
9

私はそれをプログラム的に変更する方法を知っていますが、XMLでテキストを設定したいと思います。あなたはどうやってそれをしますか?私はここで見た:http://developer.android.com/reference/android/widget/TabHost.htmlしかし、解決策は見つかりませんでした。TabHost - XMLのタブテキストを変更する方法

+0

本当に機能しましたか?私は他の人と同じ問題を抱えている。あなたはそれのために余分なJavaコードをしなければなりませんでしたか? –

答えて

9

どのように次のように見ていきます。この方法で

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <TabHost 
     android:id="@android: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:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:tag="tab0" 
        android:text="Tab 1" 
        android:background="@android:drawable/btn_star_big_on" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        /> 
       <TextView 
        android:tag="tab1" 
        android:text="Tab 2" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        /> 
       <TextView 
        android:tag="tab2" 
        android:text="Tab 3" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        /> 

      </TabWidget> 

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

       <TextView 
        android:text="Hallo1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 
       <TextView 
        android:text="Hallo2" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 
       <TextView 
        android:text="Hallo3" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 

      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

</RelativeLayout> 

....について:

TabHost

完全なタブのサンプルhereをチェックしてください。

これがうまくいきたいと思います....乾杯!

+1

これは私のためにはうまくいかなかった... – Supuhstar

+0

@ Suuhstar:あなたは何かの理由を説明できますか? – Trinimon

+5

エラーはありません、ちょうど...絶対にこれのどれも働かなかった。 'TextView'はプレビューのタブの左側に表示され、実際のデバイスで実行されるとタブは表示されません。機能は得られず、その断片はお互いに表示されます – Supuhstar

1

いつでも@ + id/tab1に移動して、タブを呼びたいものに変更できます。ですから、「About」と呼ぶには、特定のタブの線形レイアウトで@ + id/Aboutに変更します。

+0

質問はXMLについてです。あなたはxpathクエリを与える式ですか?もしそうなら、皆さんが流暢にxpathを読んでいないかもしれないという例を挙げてください。 –

+2

i18nはどうですか? – gattsbr

+0

かなり前半ですが、jorgensenはタブIDについて話していましたが、デフォルトではTabHostはIDをタブラベルとして使用しています。しかし、@ gattsbrが指摘したように、その解決法は、文字列変換ファイルを使用しない場合にのみ使用できます – STremblay

関連する問題