1

私は本当に大きな問題を抱えています。簡単なアプリケーションを作成しようとしています。そこでタブを使用していますが、tabWidget のテキストの色を動的に変更する方法が本当にわかりません。

テキストが動的に変更されるように、xml または Java コードを変更するにはどうすればよいですか?

それが私がJavaコードに持っているものです:

TabHost tabHost = (TabHost) findViewById(R.id.tabhost);

    tabHost.setup();

    TabHost.TabSpec tabSpec = tabHost.newTabSpec("creator");
    tabSpec.setContent(R.id.Card);
    tabSpec.setIndicator("Debit Card");
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("account");
    tabSpec.setContent(R.id.Account);
    tabSpec.setIndicator("Checking Account");
    tabHost.addTab(tabSpec);

それが私のxmlファイルです:

背景セレクター - tab_bg.xml:

<item android:state_selected="true" android:drawable="@drawable/tab_bg_selected"></item>
<item android:state_pressed="true" android:drawable="@drawable/tab_bg_selected"></item>
<item android:state_active="true" android:drawable="@drawable/tab_bg_selected"></item>

<item android:state_selected="false" android:drawable="@drawable/tab_bg_unselected"></item>
<item android:state_pressed="false" android:drawable="@drawable/tab_bg_unselected"></item>
<item android:state_active="false" android:drawable="@drawable/tab_bg_unselected"></item>

tab_bg_selected.xml:

   android:shape="rectangle">

<solid android:color="@color/white"/>

<corners android:bottomLeftRadius="5dp"
         android:topLeftRadius="5dp"
         android:topRightRadius="5dp"
         android:bottomRightRadius="5dp"/>
<stroke android:color="@color/blue"
        android:width="2dp"/>
</shape>

および tab_bg_unselected.xml:

   android:shape="rectangle">
<solid android:color="@color/blue"/>

<corners android:bottomLeftRadius="5dp"
         android:topLeftRadius="5dp"
         android:topRightRadius="5dp"
         android:bottomRightRadius="5dp"/>

<stroke android:color="@color/blue"
        android:width="2dp"/>

4

0 に答える 0