remove padding around action bar left icon on Android 4.0+

前端 未结 6 1883
孤街浪徒
孤街浪徒 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:34

    use custom layout for ActionBar

    enter image description here

    public class TestActivity extends Activity {
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            final ActionBar actionBar = getActionBar();
            actionBar.setCustomView(R.layout.actionbar_custom_view_home);
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setDisplayShowHomeEnabled(false);
    
            setContentView(R.layout.main);
    
        }
    
        public void Click(View v) {
            if (v.getId() == R.id.imageIcon) {
                Log.e("click on-->  ", "Action icon");
            }
        }
    }
    

    actionbar_custom_view_home.xml

    
    
        
    
        
    
    
    

提交回复
热议问题