0

I am new to android, working on my first App .I am stuck at a problem, I see extra margin in the action bar when I run my App on API 18 and above .

I googled and found this answer :- Android: remove left margin from actionbar's custom layout

But I don't think this its applicable to me, Firstly,(As per the solution suggested in the link above) 1)I am not using a toolbar, but a actionbar 2)Android Studio throws error for the below code

        Toolbar parent =(Toolbar) customView.getParent();
        parent.setContentInsetsAbsolute(0,0);

Saying, minimum is 14 and setContentInsetsAbsolute needs API 21. So I did this ,

 if(Build.VERSION.SDK_INT == 21 ){
        Toolbar parent =(Toolbar) customView.getParent();
        parent.setContentInsetsAbsolute(0,0);
 }

But this is not helping. Where am I going wrong and how to fix the issue?

njzk2
  • 38,969
  • 7
  • 69
  • 107
  • Are you using Toolbar as Action Bar via setSupportActionBar function? – Yuriy Kolbasinskiy Jul 13 '15 at 12:47
  • I am using an actionbar (Customised ). A simple Layout using relative tag , and using 'ActionBar actionBar = getActionBar(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayShowCustomEnabled(true); View customView = getLayoutInflater().inflate(R.layout.action_bar, null); actionBar.setCustomView(customView); if(Build.VERSION.SDK_INT == 21 ){ Toolbar parent =(Toolbar) customView.getParent(); parent.setContentInsetsAbsolute(0,0); } ' In the activity to set. – user3326091 Jul 14 '15 at 12:14

0 Answers0