如何在自定义创建的工具栏中更改菜单的颜色?

问题描述

我有一个主页,在该主页上创建了一个自定义工具栏,现在需要向其中添加菜单项。到目前为止,我已经成功完成了工作,并且在on模式下显示search图标(白色),但是在app:showAsAction="always"模式下添加了任何内容时,菜单指示符(三个点)显示为黑色,但我希望它们是白色。

AndroidManifest.xml

app:showAsAction="never"

actvity_homepage.xml

<activity
        android:name=".HomePage"
        android:launchMode="singleTask" />

homepage_menu.xml

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintVertical_bias="0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        app:titleTextColor="#ffffff"
        style="@style/ToolbarTheme"
        android:textAlignment="textStart"
        android:background="#2B772E"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

This is the result

解决方法

(第一种方式):

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="actionOverflowButtonStyle">@style/MyOverflowButtonStyle</item>
</style>

<style name="MyOverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
    <item name="android:tint">#62ff00</item>
</style>

或者您可以使用以下工具栏样式进行更改:

<android.support.v7.widget.Toolbar
  ...
  theme="@style/MyToolbarStyle"
/>

和您的风格:

<style name="MyToolbarStyle" parent="ThemeOverlay.AppCompat.ActionBar">
  <item name="android:textColorSecondary">#333333</item>
</style>