Change ToolBar default icon on the left

拥有回忆 提交于 2019-12-05 14:29:25

Set as NavigationIcon:

Drawable drawable = ContextCompat.getDrawable(context, R.drawable.your_drawable)
toolbar.setNavigationIcon(drawable);
setSupportActionBar(toolbar);

Try this

toolbar.setNavigationIcon(R.drawable.your_icon);

Use it before setting support action bar. And don't call this

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Or at least do

getSupportActionBar().setDisplayHomeAsUpEnabled(false);

Try it out. Some of this will work.

Add your drawable asset with size as per Material design guide and call below method in Activity onCreate

private void setUpToolBar() {
            setSupportActionBar(toolbar);
            //Set Home screen icon
            getSupportActionBar().setHomeAsUpIndicator(R.drawable.home_screen_icon);

            //Enable Home icon
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);

            //Toolbar title
            getSupportActionBar().setTitle(getString(R.string.app_name));

           //Set toolbar as action bar
            setSupportActionBar(toolbar);
        }

You can also:

mToolbar.setLogo( yourLogoID );

or you can:

mToolbar.setBackground( ContextCompat.getDrawable( yourContext, urBackgroundID );

where

mToolbar = yourToolbar;
mToolbar = findViewById(R.id.your_toolbar);
// or, if your toolbar get setted by a superclass
mToolbar = (Toolbar) getSupportActionBar();

your style should be: Blablabla.NoActionBar then in xml layout include your toolbar

If you are using a Drawer to show left Menu when Left Swiped or Home Button Clicked then you should use one of above methods (If you don't want to superclass all DrawerLayout lul)

bb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!