简体   繁体   English

Android更改ActionBar文本颜色

[英]Android change ActionBar text color

I'm using Appcompat in the App. 我在App中使用Appcompat。

How can I change the text color of the ActionBar? 如何更改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! 快乐的编码!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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