Extra padding at the left end of action bar (after updated sdk)

梦想的初衷 提交于 2019-12-13 19:16:48

问题


I don't know how this padding came up, but there's no such padding until I updated my SDK to 21. Here's my code:
    mActionBar = getSupportActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    actionBarView = LayoutInflater.from(this).inflate(R.layout.title_bar_layout, null);

    mActionBar.setCustomView(actionBarView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    mActionBar.setDisplayShowCustomEnabled(true);

Does anyone know how to solve this ? thanks.


回答1:


EDIT:

since the last update of Support library 22.1.x, if you are not using ToolBar the attributes have to be part of the ActionBar style. E.g

<style name="MyStyle" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="contentInsetStart">0dp</item>
    <item name="contentInsetEnd">0dp</item>

    <item tools:ignore="NewApi" name="android:contentInsetStart">0dp</item>
    <item tools:ignore="NewApi" name="android:contentInsetEnd">0dp</item>
</style>

and referenced by <item name="android:actionBarStyle"

OLD ANSWER

to remove the extra padding add

 <style name="AppThemeToolbar" parent="Widget.AppCompat.Toolbar">
        <item name="contentInsetStart">0dp</item>
        <item tools:ignore="NewApi" name="android:contentInsetStart">0dp</item>
 </style>

to your style.xml file. And reference it from your app theme with:

<item name="android:toolbarStyle" tools:ignore="NewApi">@style/AppThemeToolbar</item>
<item name="toolbarStyle">@style/AppThemeToolbar</item>


来源:https://stackoverflow.com/questions/28895085/extra-padding-at-the-left-end-of-action-bar-after-updated-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!