2017-01-10 61 views
0

我需要更改操作欄文本,漢堡包圖標,溢出圖標的顏色。我試過如下: -如何單獨更改操作欄項目顏色?

<!-- Title text --> 
    <item name="android:textColorPrimary">@android:color/white</item> 

    <!-- Title color in AppCompat.Light --> 
    <item name="android:textColorPrimaryInverse">@android:color/white</item> 

    <!-- Menu text--> 
    <item name="actionMenuTextColor">@android:color/white</item> 
    <!-- Overflow --> 
    <item name="android:textColorSecondary">@android:color/white</item> 
    <!-- This will change drawer icon --> 

    <item name="android:popupBackground">@android:color/white</item> 

但上面的代碼力的顏色變化在其他許多地方一樣,覆蓋彈出,編輯文本的文本顏色,有沒有辦法改變,僅在所需的地方顏色?

+0

http://stackoverflow.com/questions/33698122/android-change-actionbar-title-text-color這可能會幫助你。 –

回答

0

有更改標題的前景色在動作條

1.設置文本格式,只是這樣的3路:

Spannable text = new SpannableString(actionBar.getTitle()); 
    text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); 
    actionBar.setTitle(text); 

2.設置你的動作條的自定義視圖就是這樣的:

ActionBar actionbar = getActionBar(); 
TextView textview = new TextView(MainActivity.this); 

layoutparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 

textview.setLayoutParams(layoutparams); 
textview.setText("Action Bar Title Text"); 
textview.setGravity(Gravity.CENTER); 
textview.setTextColor(Color.parseColor("#fc6902")); 
textview.setTextSize(25); 

actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 

actionbar.setCustomView(textview); 

充分的代碼是there

3.更改使用文本顏色HTML標籤

getSupportActionBar().setTitle((Html.fromHtml("<font color=\"#FF4444\">" + getString(R.string.some_string) + "</font>"))); 
+0

我知道這一點,但我想更改導航抽屜的漢堡包圖標的顏色,我也想更改溢出圖標的顏色。 –