I'm using getSupportedActionBar().setTitle("This Phone");
I have managed to change the title color to white by using Toolbar.setTitleTextColor(0xFFFFFFFF);
How do I change the back arrow key color to white too?
You can try this in your activity :- (After setSupportActionBar(toolbar) )
Drawable backArrow = context.getResources().getDrawable(R.drawable.your_back_button);
backArrow.setColorFilter(getResources().getColor(R.color.yourcolor), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
Joy Dey.
Try to change your app theme to "Theme.AppCompat.Light.NoActionBar" in styles.xml.
<!-- 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>
</style>
Try changing the icon itself in styles.xml like this
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:homeAsUpIndicator">@drawable/ic_new_icon</item>
</style>
Try with below code :
Take image from drawable and then set color
final Drawable backArrow = getResources().getDrawable(R.drawable.back_img);
backArrow .setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(backArrow );
If you want to change color of ToolBar
title & back button image to white by style
Reference : https://stackoverflow.com/a/33339983/8448886
Add below code in your style.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 attribute app:theme="@style/ToolbarStyle"
in your toolbar
<?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>
Please have look below kotlin function which is working for me.
private fun setToolbarProperties() {
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = "" //If you don't want to set title
val upArrow = resources.getDrawable(R.drawable.ic_action_back,theme);
supportActionBar?.setHomeAsUpIndicator(upArrow);
}
Below is a toolbar xml code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@android:color/transparent"
android:orientation="vertical"
>
</androidx.appcompat.widget.Toolbar>
User contributions licensed under CC BY-SA 3.0