Android - 更改操作栏文本颜色

时间:2015-07-18 10:27:09

标签: android google-maps android-actionbar

在我的应用程序中,我有一个没有操作栏的主题,但是对于我的一个活动,我需要一个带有白色标题的操作栏。所以,这是代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/color_primary"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:title="Title"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<fragment android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below="@id/toolbar"
          android:id="@+id/map"
          android:name="com.google.android.gms.maps.SupportMapFragment"/>


</RelativeLayout>

如您所见,此活动还包含Google Maps Fragment。

结果: Result

如您所见,标题颜色不是白色。为什么?我不知道。

3 个答案:

答案 0 :(得分:3)

@Raghunandan之后:只需在AppBaseTheme中将此字符串添加到styles.xml

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

答案 1 :(得分:2)

试试这个

toolbar.setTitleTextColor(Color.WHITE);

答案 2 :(得分:0)

希望这有帮助

if(Build.VERSION.SDK_INT>=11){
            android.app.ActionBar ab=getActionBar();
            ab.setBackgroundDrawable(new ColorDrawable(0xff3b3f54));//3b3f54 is html color code for purple, you can put any desired color code like ffffff for white
            ab.setDisplayHomeAsUpEnabled(true);
}