remove padding around action bar left icon on Android 4.0+

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

    To set the height of ActionBar you can create new Theme like this one:

    
       
         
     
    

    and set this Theme to your Activity:

    android:theme="@style/Theme.BarSize"

    Now, set the height of the icons to "match_parent".

    That would remove the top and bottom padding.

    Now, the arrow at the left is inbuilt into the framework, so you have two options for a workaround:

    1. Use ActionBarSherlock. It uses it's own drwables and resources, so you can modify the arrow icon to an emty png, so that your up icon would move to extreme left.

    2. The up/back icon arises from:

    public boolean onOptionsItemSelected(MenuItem item) 
                   {
              switch (item.getItemId()) 
                    {
                    case android.R.id.home:
                                NavUtils.navigateUpFromSameTask(this);
                  return true;
                    }      
                   }
    

    So, instead of using this option for up button, you can make another actionbar option, which has an intent for the previous activity, and then place that icon on your action bar.

    It will be a bigger workaround though.

    Hope that helps.. :)

提交回复
热议问题