Android 操作栏左侧的额外边距

Android 操作栏左侧的额外边距,android,android-actionbar,android-actionbaractivity,Android,Android Actionbar,Android Actionbaractivity,我是android新手,正在开发我的第一个应用程序。我遇到了一个问题,当我在API 18和更高版本上运行我的应用程序时,我在操作栏中看到了额外的空白 我在谷歌上搜索到了这个答案:- 但我认为这不适用于我, 首先,(根据上面链接中建议的解决方案) 1) 我使用的不是工具栏,而是actionbar 2) Android Studio为以下代码抛出错误 Toolbar parent =(Toolbar) customView.getParent(); parent.s

我是android新手,正在开发我的第一个应用程序。我遇到了一个问题,当我在API 18和更高版本上运行我的应用程序时,我在操作栏中看到了额外的空白

我在谷歌上搜索到了这个答案:-

但我认为这不适用于我, 首先,(根据上面链接中建议的解决方案) 1) 我使用的不是工具栏,而是actionbar 2) Android Studio为以下代码抛出错误

        Toolbar parent =(Toolbar) customView.getParent();
        parent.setContentInsetsAbsolute(0,0);
也就是说,最小值为14,SetContentInsertSabsolute需要API 21。 所以我就这样做了,

 if(Build.VERSION.SDK_INT == 21 ){
        Toolbar parent =(Toolbar) customView.getParent();
        parent.setContentInsetsAbsolute(0,0);
 }
但这没有帮助。
哪里出了问题?如何解决问题?

您是否通过设置支持操作栏功能将工具栏用作操作栏?我使用的是操作栏(自定义)。使用相对标记并使用“ActionBar ActionBar=getActionBar()”的简单布局;actionBar.setDisplayShowHomeEnabled(false);actionBar.setDisplayHomeAsUpEnabled(false);actionBar.setDisplayShowCustomEnabled(true);View customView=GetLayoutFlater().充气(R.layout.action_bar,空);actionBar.setCustomView(customView);如果要设置的活动中存在(Build.VERSION.SDK_INT==21){Toolbar parent=(Toolbar)customView.getParent();parent.setContentInsertsAbsolute(0,0);}'。