1

アクションバー付きのタブを実装していますが、タブの背景色の変更に失敗しています。

前もって感謝します。

私の出力

ここに画像の説明を入力

私の必要な出力

ここに画像の説明を入力

その下のストリップの赤い色については、以下のコードを使用しています

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- STATES WHEN BUTTON IS NOT PRESSED -->

    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false"
          android:state_pressed="false"
          android:drawable="@color/transparent" />
    <item android:state_focused="false" android:state_selected="true"
          android:state_pressed="false"
          android:drawable="@drawable/tab_selected_example" />

    <!-- Focused states (such as when focused with a d-pad or mouse hover) -->
    <item android:state_focused="true" android:state_selected="false"
          android:state_pressed="false"
          android:drawable="@drawable/tab_unselected_focused_example" />
    <item android:state_focused="true" android:state_selected="true"
          android:state_pressed="false"
          android:drawable="@drawable/tab_selected_focused_example" />


<!-- STATES WHEN BUTTON IS PRESSED -->

    <!-- Non focused states -->
    <item android:state_focused="false" android:state_selected="false"
          android:state_pressed="true"
          android:drawable="@drawable/tab_unselected_pressed_example" />
    <item android:state_focused="false" android:state_selected="true"
        android:state_pressed="true"
        android:drawable="@drawable/tab_selected_pressed_example" />

    <!-- Focused states (such as when focused with a d-pad or mouse hover) -->
    <item android:state_focused="true" android:state_selected="false"
          android:state_pressed="true"
          android:drawable="@drawable/tab_unselected_pressed_example" />
    <item android:state_focused="true" android:state_selected="true"
          android:state_pressed="true"
          android:drawable="@drawable/tab_selected_pressed_example" />

</selector>

大文字を小文字に変更 する Sherlock のアクション バーのタブにテキストがすべて大文字で表示される

<style name="My.TabText.Style" parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
    <item name="android:textAllCaps">false</item>
     <item name="android:textSize">14sp</item>
       <item name="android:textStyle">normal</item>
</style>

アクションの色とタブの色を変更する

// set background for action bar
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0c2354")));

// set background for action bar tab
bar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0")));    
4

2 に答える 2

3

これを試してください。

                 for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
                    mTabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#01afeb")); // unselected
                    TextView tv = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
                    tv.setTypeface(Typeface.MONOSPACE);
                    //Unselected Tabs
                    tv.setTextColor(Color.parseColor("#ffffff"));
                }

                mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#f9b526")); // selected
                TextView tv = (TextView) mTabHost.getCurrentTabView().findViewById(android.R.id.title); //for Selected Tab

                tv.setTextColor(Color.parseColor("#01afeb"));
于 2015-05-21T14:48:27.833 に答える
0

たとえば、このようにアプリケーションのテーマを Holo Light に変更すると、これを行うことができます

<application android:theme="@android:style/Theme.Holo.Light" ... />

詳細については、https://developer.android.com/training/basics/actionbar/styling.htmlを参照してください。

または、たとえば次のようにテーマ全体を変更せずに:

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("FFAB00"));
于 2015-05-21T14:32:49.093 に答える