Customize Back Button

enter image description hereenter image description here

<style name="MyActionBar.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar"> <item name="android:background">@drawable/button_style</item> <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> </style> 

How can I customize the afibar navigation button up. In fact, I want it to change colors when I click on it. For example, Whatsapp, when I press the back button, the background color of the button turns blue. How can i do this?

+5
source share
2 answers

You must override android:homeAsUpIndicator for your custom theme for your project.

 <!-- Base application theme. --> <style name="AppTheme" parent="android:Theme.Holo.Light"> <item name="android:homeAsUpIndicator">@drawable/ic_action_up_caret</item> </style> 

Then set your custom as the application theme in the manifest file (if you haven't already):

 <application android:name="com.example.app" android:theme="@style/AppTheme" > 
+7
source

You can set the icon image programmatically:

 ActionBar actionBar = getActionBar(); //set icon actionBar.setIcon(some Icon); 

You can change this icon with every click.

If you want to set the color as an icon:

 ActionBar actionBar = getActionBar(); actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.niceBackgroundColor))); 
+3
source

Source: https://habr.com/ru/post/1207250/


All Articles