【问题标题】:How to remove padding from title in toolbar?如何从工具栏中的标题中删除填充?
【发布时间】:2016-07-24 16:16:20
【问题描述】:

我的工具栏

Google Play 工具栏

如何删除不必要的填充?

我的工具栏在片段内 我在片段中的代码:

public void setUpToolbar(Toolbar toolbar, String title, @DrawableRes int resId) {
    toolbar.setTitle(title);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
    ab.setHomeAsUpIndicator(resId);
    ab.setDisplayHomeAsUpEnabled(true);
}

我在 xml 中的工具栏:

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

【问题讨论】:

标签: android android-toolbar


【解决方案1】:

在您的工具栏 xml 标记中使用它

app:contentInsetStartWithNavigation="0dp"

【讨论】:

    【解决方案2】:

    只需在工具栏中添加

    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    

    它应该可以工作

    【讨论】:

      【解决方案3】:

      在你的代码中试试这个:

      ActionBar actionBar = getSupportActionBar();
      actionBar.setDisplayShowHomeEnabled(false);
      actionBar.setDisplayShowCustomEnabled(true);
      actionBar.setDisplayShowTitleEnabled(false);
      View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null);
      actionBar.setCustomView(customView);
      Toolbar parent =(Toolbar) customView.getParent();
      parent.setContentInsetsAbsolute(0,0);
      

      【讨论】:

      • @gape 现在试试,让我知道
      【解决方案4】:

      尝试添加app:contentInsetLeft:

      <android.support.v7.widget.Toolbar
                  android:id="@+id/toolbar"
                  android:layout_width="match_parent"
                  android:layout_height="?attr/actionBarSize"
                  app:layout_collapseMode="pin"
                  app:contentInsetLeft="0dp"
                  app:contentInsetStart="0dp"
                  app:popupTheme="@style/AppTheme.PopupOverlay" />
      

      【讨论】:

        【解决方案5】:

        最近遇到这个问题,即使将所有insets 设置为0dp 后,NavigationIcon 和 Title 之间仍然存在差距。显然这是 TitleView 的 Margin,要删除它,我们必须设置 app:titleMarginStart="0dp"

        所以总的来说,必须执行以下操作才能消除整个间隙。

        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp"
        app:titleMarginStart="0dp"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-03-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-07-09
          • 1970-01-01
          相关资源
          最近更新 更多