如何从工具栏中的标题中删除填充?

gap*_*ape 15 android android-toolbar

我的工具栏

我的工具栏

Google Play工具栏

GooglePlay工具栏

如何删除不必要的填充?

我的工具栏位于片段中我的代码片段:

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);
}
Run Code Online (Sandbox Code Playgroud)

我在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" />
Run Code Online (Sandbox Code Playgroud)

Abd*_*wan 29

在工具栏xml标记内使用此选项

app:contentInsetStartWithNavigation="0dp"
Run Code Online (Sandbox Code Playgroud)


Ric*_*ick 14

只需添加工具栏即可

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
Run Code Online (Sandbox Code Playgroud)

它应该工作


Nir*_*uan 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);
Run Code Online (Sandbox Code Playgroud)