首页 > 解决方案 > 如何在工具栏中将箭头颜色设为白色

问题描述

我是新开发人员。我只是在工具栏中添加了返回箭头,但它是黑色的。我怎么让它变白。下面是我的代码:

爪哇

setSupportActionBar(newToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

文件

    <android.support.v7.widget.Toolbar
    android:id="@+id/newToolBarId"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</android.support.v7.widget.Toolbar>

标签: android

解决方案


我通过编辑styles.xml解决了它:

<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#ffffff</item>

...然后在活动的工具栏定义中引用样式:

<LinearLayout
android:id="@+id/main_parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    app:theme="@style/ToolbarColoredBackArrow"
    app:popupTheme="@style/AppTheme"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"/>

推荐阅读