0

I want make an action bar but back indicator and text has to be different colors. How can I achieve this?

enter image description here

When I use this:

    getSupportActionBar().setHomeAsUpIndicator(ContextCompat.getDrawable(getApplicationContext(), R.drawable.back));

it becomes something weird: enter image description here

[enter image description here2

The picture I'm using is this: enter image description here

2 Answers2

1

You can use image for back button as :

supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(getDrawable(R.drawable.back))

and for title text color you have make changes in your theme

<style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primaryDark</item>
        <item name="colorAccent">@color/highlightRed</item>
        <item name="actionBarTheme">@style/ToolbarStyle</item>
</style>

<style name="ToolbarStyle" parent="Widget.AppCompat.ActionBar">
        <item name="android:textColorPrimary">@color/white</item>
</style>
yogesh lokhande
  • 1,245
  • 1
  • 11
  • 20
1

Try below code, Put this code inside your onCreate() of the activity :

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));
getSupportActionBar().setHomeAsUpIndicator(getDrawable(R.drawable.back_button));

If you are facing issue with getSupportActionBar() use getActionBar()

or, you can create a custom toolbar to achieve this :

Look into this : Android toolbar center title and custom font

For fixing your image issue you can go with below sites :

Download any backimage from this site and put in mipmap/drawable folder of android studio all 5 images for different size. https://materialdesignicons.com/

Or, Use this site to convert your image in 5 different sizes : romannurik.github.io

enter image description here

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44