How to change home as up resource programmatically?

前端 未结 6 1666
迷失自我
迷失自我 2020-12-25 15:02

I know how to change the homeAsUpIndicator in the styles xml file. The question is how to change it programmatically.

The reason I want to do it bec

6条回答
  •  情歌与酒
    2020-12-25 15:30

    The solution by @matthias doesn't work on all devices, A better solution to change the homeAsUpIndicator is to set it @null in style and change the logo resource programmatically.

    Below is my code from style.xml

    
    

    In code you can change the logo using setLogo() method.

    getSupportActionBar().setLogo(R.drawable.abc_ic_ab_back_holo_light); //for ActionBarCompat
    getActionBar().setLogo(R.drawable.abc_ic_ab_back_holo_light); //for default actionbar for post 3.0 devices
    

    Also note that the Android API 18 has methods to edit the homeAsUpIndicator programatically, refer documentation.

提交回复
热议问题