Android:更改工具栏中后退按钮的颜色

时间:2017-03-17 19:20:37

标签: java toolbar back-button

我试图让工具栏上的后退按钮变黑,但我无法找到方法。出于某种原因,我的xml文件中没有toolBar,因此无法为我更改颜色。如果有其他方法,请告诉我。

Photo of toolbar

我有primaryColor白色,但后退按钮也是白色。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlNormal">@color/colorPrimaryDark</item>
    <item name="actionMenuTextColor">@color/colorPrimaryDark</item>
</style>

这是我的xml文件

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Space
        android:layout_width="match_parent"
        android:layout_height="40dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:id="@+id/taskNameEditText"
        android:textAlignment="center"
        android:hint="enter task name"/>

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/scrollLinearLayout">

        </LinearLayout>
    </HorizontalScrollView>

    <Space
        android:layout_width="match_parent"
        android:layout_height="40dp" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/fromTimeEditText"
            android:layout_weight="1"
            android:hint="fromTime"
            android:textAlignment="center" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/toTimeEditText"
            android:layout_weight="1"
            android:hint="toTime"
            android:textAlignment="center" />
    </LinearLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

如果您使用的是工具栏,则可以更改

toolbar.getNavigationIcon().setColorFilter(getResources().getColor(R.color.blue_gray_15), PorterDuff.Mode.SRC_ATOP);
相关问题