2017-06-05 86 views
0

我正在开发一个android应用程序,我想让工具栏的标题为白色。如何更改Android中工具栏标题的颜色?

我已删除默认的工具栏和补充工具栏到我的活动,但无法弄清楚如何将工具栏的标题的颜色更改为白色

MainActivity.java

package com.example.acer.videoapp; 

import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 


public class MainActivity extends AppCompatActivity { 

    Toolbar toolbar; 
    ListView listView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     toolbar.setTitle(getResources().getString(R.string.app_name)); 
     //toolbar.setTitleTextColor(white); 
     listView = (ListView) findViewById(R.id.listView); 


     ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_expandable_list_item_1,getResources().getStringArray(R.array.subjects)); 

     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int i, long id) { 
       Intent intent = new Intent(MainActivity.this, SecondActivity.class); 
       intent.putExtra("Subject", listView.getItemAtPosition(i).toString()); 
       startActivity(intent); 
      } 
     }); 
     listView.setAdapter(mAdapter); 

    } 
} 
+0

toolbar.setTitleTextColor(白色)是不工作的Toolbar文本的颜色? – sasikumar

+0

没有工作,我不知道为什么 – Dilinieee

回答

2

设置使用toolbar.setTitleTextColor()方法

toolbar = (Toolbar) findViewById(R.id.toolbar); 
toolbar.setTitle(getResources().getString(R.string.app_name)); 
toolbar.setTitleTextColor(getColor(R.color.white)); 
1

修改您的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/white</item> 
     </style> 
    </resources> 

的风格,那么分配到工具栏

<android.support.v7.widget.Toolbar 
    ... 
    app:theme="@style/MyTheme"> 

</android.support.v7.widget.Toolbar> 
相关问题