Actionbar中后退箭头的颜色不会更改

时间:2017-06-23 18:36:48

标签: android android-actionbar

某些活动中的标题和后退箭头显示为白色,部分显示为黑色。 我在Stackoverflow中阅读并应用了所有解决方案,但没有一个能够工作 在一些活动中代码工作正常,但其中一些没有!

我的风格:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowBackground">@drawable/launch_screen</item>

</style>

<style name="NormalTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

这不起作用:

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="de.h_da.pizzaorder.Activities.NewUserActivity"><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/NewUserActivity_Toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        />

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

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="top"
        android:scrollbars="vertical"
        >

        <TextView
            style="@style/TextView"
            android:text="@string/NewUserActivity_Username_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_Username_EditText"
            style="@style/EditText"
            android:hint="@string/NewUserActivity_HintUsername_EditText"
            android:maxLength="40"/>

        <TextView
            android:id="@+id/NewUserActivity_Password_TextView"
            style="@style/TextView"
            android:text="@string/NewUserActivity_Password_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_Password_EditText"
            style="@style/EditText"
            android:hint="@string/NewUserActivity_HintPassword_EditText"
            android:inputType="textPassword"
            android:maxLength="45"/>

        <TextView
            android:id="@+id/NewUserActivity_RePassword_TextView"
            style="@style/TextView"
            android:text="@string/NewUserActivity_RePassword_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_RePassword_EditText"
            style="@style/EditText"
            android:hint="@string/NewUserActivity_HintRePassword_EditText"
            android:inputType="textPassword"
            android:maxLength="45"/>

        <TextView
            style="@style/TextView"
            android:text="@string/NewUserActivity_Name_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_Name_EditText"
            style="@style/EditText"
            android:hint="@string/NewUserActivity_HintName_EditText"
            android:maxLength="40"/>

        <TextView
            style="@style/TextView"
            android:text="@string/NewUserActivity_Family_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_Family_EditText"
            style="@style/EditText"
            android:hint="@string/NewUserActivity_HintFamily_EditText"
            android:maxLength="40"/>

        <TextView
            style="@style/TextView"
            android:text="@string/NewUserActivity_Email_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_Email_EditText"
            style="@style/EditText"
            android:hint="@string/NewUserActivity_HintEmail_EditText"
            android:inputType="textEmailAddress"
            android:maxLength="40"/>


        <TextView
            style="@style/TextView"
            android:text="@string/NewUserActivity_Telephone_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_Telephone_EditText"
            style="@style/EditText"
            android:hint="@string/NewUserActivity_HintTelephone_EditText"
            android:inputType="phone"
            android:maxLength="13"/>

        <TextView
            style="@style/TextView"
            android:text="@string/NewUserActivity_Address_TextView" />

        <EditText
            android:id="@+id/NewUserActivity_Address_EditText"
            style="@style/EditText"
            android:maxLength="500"
            android:scrollbars="vertical"
            android:hint="@string/NewUserActivity_HintAddress_EditText"
            android:layout_height="match_parent"
            android:imeOptions="actionDone"/>


        <Button
            android:id="@+id/NewUserActivity_Create_Button"
            style="@style/Button"
            android:text="@string/NewUserActivity_Create_Button" />

    </LinearLayout>
</ScrollView>
</LinearLayout>

在这项工作中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="de.h_da.pizzaorder.Activities.SettingsActivity">

    <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/SettingsActivity_Toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <ListView
        android:id="@+id/SettingsActivity_ListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@null"/>

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

要使工具栏的“后退”箭头和溢出图标变亮,同时保持以灯光为主题的弹出菜单:

在您的style.xml文件中添加工具栏样式:

<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

将新样式设置为工具栏布局:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    style="@style/AppTheme.Toolbar"/> <!-- Added style -->

这将为您的工具栏提供深色主题(白色)箭头和溢出图标,但会使弹出菜单保持亮起。

来自(原始链接)此处:https://stackoverflow.com/a/33833931/2905354

这非常有效,并具有使您的应用更易于主题化的附加好处。

答案 1 :(得分:0)

我遇到了这个问题,我只是尝试将自己的drawable设置为这样的后退按钮:

final Drawable your_drawable = getResources().getDrawable(R.drawable.back_arrow);
upArrow.setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(your_drawable);