2014-12-20 41 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);