【问题标题】:Extra padding at the left end of action bar (after updated sdk)操作栏左端的额外填充(更新 sdk 后)
【发布时间】:2015-05-07 18:50:17
【问题描述】:

我不知道这个填充是怎么出现的,但是直到我将我的 SDK 更新到 21 才出现这样的填充。 这是我的代码:

    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);

有谁知道如何解决这个问题?谢谢。

【问题讨论】:

  • 请发布您的 R.layout.title_bar_layout 布局文件的代码

标签: android android-actionbar padding


【解决方案1】:

编辑:

自上次更新支持库22.1.x 以来,如果您不使用ToolBar,属性必须是ActionBar 样式的一部分。例如

<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>

并被&lt;item name="android:actionBarStyle"引用

老答案

删除多余的填充添加

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

到您的 style.xml 文件。并从您的应用主题中引用它:

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

【讨论】:

  • 我使用了这个代码Toolbar parent =(Toolbar) customView.getParent(); parent.setContentInsetsAbsolute(0,0);,这解决了我的问题。无论如何,谢谢你的回答。
  • 它做同样的事情,如你所见。它设置setContentInsets
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-10
  • 1970-01-01
相关资源
最近更新 更多