android - 如何删除向上导航箭头和工具栏标题之间的填充?
问题描述
顶部是您设置时向上导航箭头的默认填充
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
我希望工具栏看起来更像底部图像,因为我希望标题指示向上导航箭头将用户发送到的位置,而不是对当前活动的描述。到目前为止,我已经尝试将自定义文本视图添加到工具栏,并app:contentInsetStartWithNavigation="0dp"
根据这个 类似的问题进行设置。但正如作者所指出的,这不会删除箭头右侧的填充。如何让工具栏看起来更像第二张图片?我的工具栏的当前 xml 如下:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_doc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:contentInsetStartWithNavigation="0dp"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:gravity="left"
android:id="@+id/txtTitle"
android:textColor="#FFFFFF"/>
</android.support.v7.widget.Toolbar>
我进一步提供了菜单的 xml,我使用菜单充气器将其添加到工具栏。我漂浮的另一个解决方案是向菜单本身添加箭头图标和文本视图?但是我不确定如何为新箭头图标提供相同的向上导航行为。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_baseline_home_24px"
app:showAsAction="always"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
解决方案
尝试设置app:contentInsetStart
为0dp
而不是app:contentInsetStartWithNavigation
.
<android.support.v7.widget.Toolbar
...
app:contentInsetStart="0dp">
推荐阅读
- c - 您可以使用 C 阵列“破解”窗口,还是以某种方式安全?
- azure - AzureAD MaxAgeSessionMultiFactor 不工作
- arrays - 将数字放入 AX 时,AH 中的数字错误
- c# - ASP.NET EF Core 使用外键插入多个表
- admob - AdMob - RewardedVideoAd - 没有可用视频时的最佳做法 (errorCode = 3)
- javascript - 反应路由器开关未按预期工作
- c# - 位图流到c#中的视频howto?
- java - 在包子目录中运行特定类的 main
- javascript - 根据 1 个特定值的标识将对象拆分为多个有序数组
- java - 如何防止执行在执行程序队列中等待空闲线程的任务