In my app I've got a theme without an action bar, but for one of my activities I need an action bar with white title. So, here is it's code:
<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>
As you see, this activity also contains Google Maps Fragment.
Result:
As you see, title color is not white. Why? I wonder.
@Raghunandan之后:只需在styles.xml
将此字符串添加到您的AppBaseTheme
中:
<item name="android:textColorPrimary">@android:color/white</item>
尝试这个
toolbar.setTitleTextColor(Color.WHITE);
Hope this helps
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.