Search code examples
javaandroidandroid-actionbarcoding-styleback-button

How to change action bar button in android


I want to make the back button in the action bar to look like this "<" and not arrow like "<-". Please let me know how to do it.


Solution

  • In you activity onCreate() method do this:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        ........
        ................
    
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.icon_arrow);
    
        ..........
        ...................
    }   
    

    OUTPUT:

    enter image description here

    For Icon:

    If you are using Android Studio, then you can easily add icons.

    1. Right click on drawable folder > New > Image Asset
    2. Choose icon type "Actionbar and Tab icons"
    3. Click on Clip art to choose your desired icon
    4. Change theme as per your needs > Next
    5. Finish

    enter image description here