2011-10-16 14 views
1

私はタブレイアウトを使用していると私は二つのことをしたい:テキストサイズを縮小 アンドロイド:タブ上のテキストや色、タブのレイアウト

  • グレーではありませんので

    1. は、色を設定します、テキストは適合しません。

    また、テキストはほとんどの部分ではなくアイコンの下にあります(私はそれについて何かできますか?)。

    どうすればいいですか?

    編集:私は、このように新しいタブを作成しています:私は言葉「アーティスト」の大きさを変更したい

    spec = tabHost.newTabSpec("artists").setIndicator(
        "Artists", 
        res.getDrawable(R.drawable.ic_tab_artists) 
    ).setContent(intent); 
    tabHost.addTab(spec); 
    

    。オプションAについては

  • 答えて

    5

    独自のビューを定義する必要があります。

    tabHost.newTabSpec("tab1") 
           .setIndicator(prepareTabView(this, "title")) 
           .setContent(intent); 
    

    、あなたがテキストのサイズ、ここでtv.setTextSizeを変更することができます(20) "

    public static View prepareTabView(Context context, String text) { 
         View view = LayoutInflater.from(context).inflate(
           R.layout.tab_indicator, null); 
         TextView tv = (TextView) view.findViewById(R.id.tabIndicatorTextView); 
         tv.setText(text); 
    
         return view; 
        } 
    

    tab_indicator.xmlはあなたがここにテキストサイズもアンドロイド変更することができます。TEXTSIZE =" 20dipを"ここで背景色を設定することが可能であるアンドロイド:背景=" @カラー/ back_color_selector_tab」

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/fakeNativeTabLayout" android:layout_width="wrap_content" 
        android:layout_height="wrap_content" android:gravity="center" 
        android:orientation="vertical" android:background="@color/back_color_selector_tab"> 
        <!-- You can even define an Icon here (dont forget to set a custom icon 
         in your code for each Tab): <ImageView android:id="@+id/fakeNativeTabImageView" 
         android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:src="@drawable/icon" /> --> 
        <TextView android:id="@+id/tabIndicatorTextView" 
         android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:text="Tab" android:ellipsize="marquee" /> 
    
    </LinearLayout> 
    

    back_color_selector_tab.xmlは、さまざまな州の背景色が自動的に変更されるxmlです。

    <?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
        <item android:state_pressed="true" android:drawable="@drawable/state_orange" /> 
        <item android:state_selected="true" android:drawable="@drawable/background05" /> <!-- focused --> 
        <item android:drawable="@drawable/background04" /> <!-- default --> 
    </selector> 
    

    state_orange.xml

    <?xml version="1.0" encoding="UTF-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle"> 
        <solid android:color="@color/orange" /> 
    </shape> 
    
    +1

    コードの各部分が何をしているのか説明できますか? 私はそれがどのようにAとB ... – Belgi

    +0

    このサンプルではすべてのものがあなたの手にあり、tab_indicator.xmlファイルの設計に依存して – breceivemail

    +0

    私はそのコードを使用してみました。 prepareTabViewそれはR.layout.tab_indicatorを認識しません B.ヘックストリプレット(#007FFFなど)で色を選択できますか? C. はエラーです... – Belgi

    0

    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
        { 
         tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#8A4117")); 
        } 
         tabHost.getTabWidget().setCurrentTab(1); 
         tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#C35817")); 
    
    +0

    のサンプルあなたがのために後の2行を説明してくださいできますか? なぜtabHost.getTabWidget()。setCurrentTab(0)、そして最後の行がその特定のタブのバックグラウンドカラーを変更しないのですか? – Belgi

    +0

    現在のタブの背景を異なる色で強調表示するために使用します。そして、OnTabChangeListenerを実装して、選択したタブを別のバックグラウンドで強調表示し、次に非選択のタブ –

    +0

    ありがとう、タブ下のそのラインの色を変更することも可能ですか? – Belgi

    関連する問題