2014-12-20 37 views
0

我似乎無法弄清楚,爲什麼我不能改變操作欄文本的文本顏色..改變Android的動作條標題顏色

我一直在嘗試了許多風格的組合,我似乎沒有看到爲什麼其中一個還沒有工作。

我正在使用自定義字體,並認爲它可能與字體有關,但我自此嘗試改變原生字體的顏色。下面你可以找到我目前的位置,我嘗試了一些分層的樣式,但無濟於事。有沒有人遇到過這個問題?

這是我在改變操作欄文本顏色

<resources> 
<style name="AppTheme" parent="Theme.AppCompat"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/teal_500</item> 
    <item name="android:actionBarStyle">@style/ActionBarStyle</item> 
</style> 

<style name="ActionBarStyle" 
     parent="Widget.AppCompat.ActionBar"> 
    <item name="android:background">@color/teal_500</item> 
    <item name="android:titleTextStyle">@style/ActionBarTitleColor</item> 
</style> 

<style name="ActionBarTitleColor" parent="TextAppearance.AppCompat.Widget.ActionBar.Title"> 
    <!-- Customize your theme here. --> 
    <item name="android:textColor">@color/teal_50</item> 
</style> 
</resources> 

這裏最新的嘗試是其主要活動

public class MainActivity extends ActionBarActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    configureTitle(); 
} 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

private void configureTitle(){ 
    // SpannableString s = new SpannableString("Photoswap"); 
    //s.setSpan(new TypefaceSpan(this, "Pacifico.ttf"), 0, s.length(), 
      // Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

    // Update the action bar title with the TypefaceSpan instance 
    // ActionBar actionBar = getSupportActionBar(); 
    // actionBar.setTitle(s); 


} 

}

回答

0

STEP 1:抓住action_bar_title的編號

int titleId = getResources().getIdentifier("action_bar_title", "id", "android"); 

STEP 2:使用TextView的

TextView abTitle = (TextView) findViewById(titleId); 
abTitle.setTextColor(colorId);