简体   繁体   中英

Android change ActionBar text color

I'm using Appcompat in the App.

How can I change the text color of the ActionBar? I've tried a personalized theme but it doesn't work

<style name="AppTheme" parent="Theme.AppCompat.Light">        
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:textColor">#000080</item>
</style>

Since the Toolbar is like any other view, you can change the way you want your text to look like particularly the title text:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <TextView
            android:id="@+id/custom_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:textColor="@color/colorRed"
            android:text="@string/title_activity_mainr"/>
    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

This should help change the text color.

In fact, you can change the position of the title text as you wish!

Happy coding!

如果这是解决问题的唯一方法我单独这样做没有任何问题,我不想因为我的懒惰而改变

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM