How to customize the back button on ActionBar

后端 未结 9 1161
抹茶落季
抹茶落季 2020-11-22 17:12

I have been able to customize the action bar\'s background, logo image and text color using suggestions from these:
Android: How to change the ActionBar "Home"

相关标签:
9条回答
  • 2020-11-22 17:27

    If you are using Toolbar, you don't need those solutions. You only have to change the theme of the toolbar

    app:theme="@style/ThemeOverlay.AppCompat.Light"
    
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    

    If you are using a dark.actionBar your back button is going to be white else if you are using light actionbar theme it is going to be black.

    0 讨论(0)
  • 2020-11-22 17:32

    I did the below code onCreate() and worked with me

    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_yourindicator);
    
    0 讨论(0)
  • 2020-11-22 17:35

    tray this:

    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close);
    

    inside onCreate();

    0 讨论(0)
  • 2020-11-22 17:38

    So you can change it programmatically easily by using homeAsUpIndicator() function that added in android API level 18 and upper.

    ActionBar().setHomeAsUpIndicator(R.drawable.ic_yourindicator);

    If you use support library

    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_yourindicator);

    0 讨论(0)
  • 2020-11-22 17:40

    I had the same issue of Action-bar Home button icon direction,because of miss managing of Icon in Gradle Resource directory icon

    like in Arabic Gradle resource directory you put icon in x-hdpi and in English Gradle resource same icon name you put in different density folder like xx-hdpi ,so that in APK there will be two same icon names in different directories,so your device will pick density dependent icon may be RTL or LTR

    0 讨论(0)
  • 2020-11-22 17:44

    I used back.png image in the project menifest.xml file. it is fine working in project.

    <activity
            android:name=".YourActivity"
             android:icon="@drawable/back"
            android:label="@string/app_name" >
        </activity>
    
    0 讨论(0)
提交回复
热议问题