I could not change the color of back button. I am using toolbar material design. In my app I am applying black background of tool bar but the back design is being black by default that's why I just want to change the color of this back button. Please give me solutions.
我无法改变后退按钮的颜色。我正在使用工具栏材料设计。在我的应用程序中,我应用工具栏的黑色背景,但默认情况下背面设计为黑色,这就是为什么我只想更改此后退按钮的颜色。请给我解决方案。
Thank You
谢谢
7 个解决方案
#1
34
use this style
使用这种风格
<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">@drawable/back_button_image</item>
</style>
#2
88
You can add a style to your styles.xml,
您可以为styles.xml添加样式,
<style name="ToolbarStyle" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- Customize color of navigation drawer icon and back arrow -->
<item name="colorControlNormal">@color/toolbar_color_control_normal</item>
</style>
and add this as theme to your toolbar in toolbar layout.xml using app:theme, check below
并使用app:theme将其作为主题添加到工具栏layout.xml中的工具栏中,请在下面查看
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ToolbarStyle" >
</android.support.v7.widget.Toolbar>
#3
57
Here is the simplest way of achieving Light and Dark Theme for Toolbar.You have to change the value of app:theme
of the Toolbar tag
这是实现工具栏的浅色和深色主题的最简单方法。您必须更改工具栏标签的app:theme的值
- For Black Toolbar Title and Black Up arrow, your toolbar should implement following theme:
- 对于黑色工具栏标题和黑色向上箭头,您的工具栏应实现以下主题:
app:theme="@style/ThemeOverlay.AppCompat.Light"
应用:主题= “@风格/ ThemeOverlay.AppCompat.Light”
- For White Toolbar Title and White Up arrow, your toolbar should implement following theme:
- 对于白色工具栏标题和白色向上箭头,您的工具栏应实现以下主题:
app:theme="@style/ThemeOverlay.AppCompat"
应用:主题= “@风格/ ThemeOverlay.AppCompat”
#4
17
Tried all suggestions above. The only way that I managed to change the color of navigation icon default Back button arrow in my toolbar is to set colorControlNormal
in base theme like this. Probably due to the fact that the parent is using Theme.AppCompat.Light.NoActionBar
试过上面的所有建议。我设法更改工具栏中导航图标默认后退按钮箭头的颜色的唯一方法是在这样的基本主题中设置colorControlNormal。可能是由于父级使用的是Theme.AppCompat.Light.NoActionBar
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">@color/white</item>
//the rest of your codes...
</style>
#5
13
For white Toolbar Title and White Up arrow, use following theme:
对于白色工具栏标题和白色向上箭头,请使用以下主题:
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
#6
6
Try this,
尝试这个,
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.grey), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
#7
3
I think if theme should be generated some problem but its dynamically set black arrow.So i Suggested try this one.
我认为如果主题应该生成一些问题,但它动态设置黑色箭头。所以我建议尝试这一个。
Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
backArrow.setColorFilter(getResources().getColor(R.color.md_grey_900), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
#1
34
use this style
使用这种风格
<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">@drawable/back_button_image</item>
</style>
#2
88
You can add a style to your styles.xml,
您可以为styles.xml添加样式,
<style name="ToolbarStyle" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- Customize color of navigation drawer icon and back arrow -->
<item name="colorControlNormal">@color/toolbar_color_control_normal</item>
</style>
and add this as theme to your toolbar in toolbar layout.xml using app:theme, check below
并使用app:theme将其作为主题添加到工具栏layout.xml中的工具栏中,请在下面查看
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ToolbarStyle" >
</android.support.v7.widget.Toolbar>
#3
57
Here is the simplest way of achieving Light and Dark Theme for Toolbar.You have to change the value of app:theme
of the Toolbar tag
这是实现工具栏的浅色和深色主题的最简单方法。您必须更改工具栏标签的app:theme的值
- For Black Toolbar Title and Black Up arrow, your toolbar should implement following theme:
- 对于黑色工具栏标题和黑色向上箭头,您的工具栏应实现以下主题:
app:theme="@style/ThemeOverlay.AppCompat.Light"
应用:主题= “@风格/ ThemeOverlay.AppCompat.Light”
- For White Toolbar Title and White Up arrow, your toolbar should implement following theme:
- 对于白色工具栏标题和白色向上箭头,您的工具栏应实现以下主题:
app:theme="@style/ThemeOverlay.AppCompat"
应用:主题= “@风格/ ThemeOverlay.AppCompat”
#4
17
Tried all suggestions above. The only way that I managed to change the color of navigation icon default Back button arrow in my toolbar is to set colorControlNormal
in base theme like this. Probably due to the fact that the parent is using Theme.AppCompat.Light.NoActionBar
试过上面的所有建议。我设法更改工具栏中导航图标默认后退按钮箭头的颜色的唯一方法是在这样的基本主题中设置colorControlNormal。可能是由于父级使用的是Theme.AppCompat.Light.NoActionBar
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlNormal">@color/white</item>
//the rest of your codes...
</style>
#5
13
For white Toolbar Title and White Up arrow, use following theme:
对于白色工具栏标题和白色向上箭头,请使用以下主题:
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
#6
6
Try this,
尝试这个,
final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(getResources().getColor(R.color.grey), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
#7
3
I think if theme should be generated some problem but its dynamically set black arrow.So i Suggested try this one.
我认为如果主题应该生成一些问题,但它动态设置黑色箭头。所以我建议尝试这一个。
Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
backArrow.setColorFilter(getResources().getColor(R.color.md_grey_900), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow);