remove padding around action bar left icon on Android 4.0+

前端 未结 6 1896
孤街浪徒
孤街浪徒 2020-11-29 01:57

I want to remove the padding around the icon on the left in the standard android 4.0+ action bar. I\'m setting the icon with:

getActionBar().setIcon(getResou         


        
6条回答
  •  野性不改
    2020-11-29 02:51

    you can find homeview in actionbarview define like this:

    
    
    
    

    but you cannot get upView by findViewById(android.R.id.up).

    so you can get homeView and get its parent view ,set upview width 0

        ImageView view = (ImageView)findViewById(android.R.id.home);
        if(view.getParent() instanceof ViewGroup){
            ViewGroup viewGroup = (ViewGroup)view.getParent();
            View upView = viewGroup.getChildAt(0);
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) upView.getLayoutParams();
            layoutParams.width = 0;
            upView.setLayoutParams(layoutParams);
        }
    

提交回复
热议问题