Change the size of hamburger icon in toolbar?

安稳与你 提交于 2019-12-10 17:26:40

问题


I have 2 questions which can be strange but anyway...

I have toolbar with a title of application. How to change it to picture which is not the logo?

The next question: Is it possible to set, change the size of hamburger icon in toolbar? I made classic navigation drawer with the help of next code below (I used ActionBarDrawerToggle also) but the size is too small if you will compare it with another items(icons) of my toolbar.

toolbar = (Toolbar) findViewById(R.id.application_toolbar);
setSupportActionBar(toolbar);

getSupportActionBar().setDisplayShowHomeEnabled(true);

NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment)getFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer,(DrawerLayout)findViewById(R.id.drawer_layout), toolbar );

Thanks for any help! =)


回答1:


I had solved this problem by this way:

for (int i = 0; i < mToolbar.getChildCount(); i++) {
   if(mToolbar.getChildAt(i) instanceof ImageButton){
       mToolbar.getChildAt(i).setScaleX(1.5f);
       mToolbar.getChildAt(i).setScaleY(1.5f);
   }
}

and my hamburger icon size had been increased.




回答2:


I wanted to increase the size of the Hamburger button and found other answers to not work. Code from this answer worked perfectly and is pasted below.

"Create a custom class which extends the Drawable class to create the hamburger and navigation icons. There are various methods to change the size of either but below are the methods which control the hamburger icon."

public class HamburgerDrawable extends DrawerArrowDrawable {

    public HamburgerDrawable(Context context){
        super(context);
        setColor(context.getResources().getColor(R.color.white));
    }

    @Override
    public void draw(Canvas canvas){
        super.draw(canvas);

        setBarLength(30.0f);
        setBarThickness(5.0f);
        setGapSize(5.0f);
    }
}

"Then call it from your class:"

private void increaseHamburgerSize(){
    mDrawerToggle.setDrawerArrowDrawable(new HamburgerDrawable(this));
}


来源:https://stackoverflow.com/questions/28152018/change-the-size-of-hamburger-icon-in-toolbar

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