我的问题是抽屉导航图标和工具栏标题之间的额外空间。示例图片如下:
工具栏的xml View 是
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:popupTheme="@style/AppTheme.PopupOverlay" />
我已尝试使用以下代码解决此问题,但未发生任何更改。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//toolbar.setTitleMarginStart(0);
toolbar.setTitleMarginStart(-8);
}
有什么办法可以解决这个问题吗?
最佳答案
添加
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
到工具栏
。
完整代码:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextAppearance="@style/Toolbar.TitleText"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp" />
关于android - 如何缩小导航图标和工具栏标题之间的差距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40717684/