2014-03-29 49 views
2

如何將我的操作欄文本顏色從白色更改爲黑色?我不想使用行動條Sherlock。 enter image description here如何更改操作欄文本顏色

這裏是我的代碼行動酒吧。

ActionBar ab = getActionBar(); 
    ab.setDisplayUseLogoEnabled(false); 
    ab.setDisplayShowHomeEnabled(true); 
    ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    ab.setCustomView(R.layout.actionbar); 
    ab.setDisplayHomeAsUpEnabled(true); 
    ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#33CCFF"));  
    ab.setBackgroundDrawable(colorDrawable); 

這是自定義視圖操作欄:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:orientation="vertical"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="@string/title" 
    android:textColor="#ffffff" 
    android:textSize="24sp" /> 
</LinearLayout> 

這裏style.xml:

<resources> 
    <style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light"> 
    </style> 
    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
    </style> 
</resources> 

我可以知道什麼是實現我目標的正確途徑也許這個問題太基本了,但我沒有找到任何合適的解決方案。請幫助我。

+0

u需要更改短語「註冊」的顏色? – kathir

+0

http://stackoverflow.com/questions/5861661/actionbar-text-color將幫助你 –

+0

是@kathir。我該如何改變? –

回答

0

嘗試這個風格:

您可以編輯TitleTextStyle款式裏面:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light"> 
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
    </style> 

    <style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar"> 
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> 
    </style> 

    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title"> 
    <item name="android:textColor">@color/black</item> 
    </style> 
</resources> 
0

這裏是styles.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="MyTheme" parent="@android:style/Theme.Holo.Light"> 
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
</style> 

<style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar"> 
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> 
</style> 

<style name="MyTheme.ActionBar.TitleTextStyle" 
parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title"> 
<item name="android:textColor">@color/red</item> 
</style></resources> 

感謝名單,以rnoway

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:orientation="vertical"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="@string/title" 
    android:textColor="#ffffff"  // change the color code your wat , instead of #ffffff put youra 
    android:textSize="24sp" /> 

ü可以從

http://www.w3schools.com/tags/ref_colorpicker.asp

0

找到顏色代碼只需使用HTML設置標題,並指定文本顏色。例如,要將ActionBar文本顏色設置爲紅色,只需執行以下操作:

getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color=\"#000000\">" + getString(R.string.app_name) + "</font>"));