如何在透明的应用程序栏中更改android应用程序名称文本颜色

2uluyalo  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(382)

我想用透明的应用程序栏和图像背景将我的应用程序名称颜色设置为灰色。然而,由于某些原因,应用程序名称的颜色保持为白色。下面是我的代码。有什么建议吗?提前谢谢你!

1. Themes.xml

     <resources xmlns:tools="http://schemas.android.com/tools">
        <!-- Base application theme. -->
        <style name="Theme.DailyBread" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
            <!-- Primary brand color. -->
            <item name="colorPrimary">@color/purple_500</item>
            <item name="colorPrimaryVariant">@color/purple_700</item>
            <item name="colorOnPrimary">@color/white</item>
            <!-- Secondary brand color. -->
            <item name="colorSecondary">@color/teal_200</item>
            <item name="colorSecondaryVariant">@color/teal_700</item>
            <item name="colorOnSecondary">@color/black</item>
            <!-- Status bar color. -->
            <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
            <!-- Customize your theme here. -->
        </style>
        <style name="AppTheme.ActionBar.Transparent" parent="Theme.DailyBread">
            <item name="titleTextColor">@color/gray_dark</item>
            <item name="android:textColorPrimary">@color/gray_dark</item>
            <item name="android:windowContentOverlay">@null</item>
            <item name="windowActionBarOverlay">true</item>
            <item name="colorPrimary">@android:color/transparent</item>
            <item name="android:windowTranslucentStatus">true</item>
            <item name="android:windowTranslucentNavigation">true</item>
        </style>
    </resources>

 2. color.xml
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="purple_200">#FFBB86FC</color>
        <color name="purple_500">#FF6200EE</color>
        <color name="purple_700">#FF3700B3</color>
        <color name="teal_200">#FF03DAC5</color>
        <color name="teal_700">#FF018786</color>
        <color name="black">#FF000000</color>
        <color name="white">#FFFFFFFF</color>
        <color name="gray_dark">#696665</color>
        <color name="gary_light">#bdbab9</color>
    </resources>
5hcedyr0

5hcedyr01#

创建您的 toolbar.xml 背景为 AppBarLayout@null :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
    android:id="@+id/general_appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Application Name"
            android:textSize="42sp"/>
    </android.support.v7.widget.Toolbar>

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

附言:你也可以使用 android:background="@android:color/transparent" 而不是 @null .
结果:

相关问题