android - 我怎样才能使小吃栏位于导航栏上方?(y轴)
问题描述
我有这个布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/non_clickable_account_snackbar_constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/my_snackbar_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/my_snackbar_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/show_account_snackbar"
android:theme="@style/Theme.GoogleMaterial.DayNight.Bridge"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
我有一个自定义课程:
public final class MySnackbar<AccountT>
extends BaseTransientBottomBar<MySnackbar<myT>> {
和
super(findTopMostFrameLayout(parent), content, new MySnackbarAnimation(content));
和
调用时"show()"
,它会显示一个具有自定义布局的 android 小吃店。
当我显示 amy_snackbar
时,它会在底部导航栏(z 轴)下方看到。
1)我怎样才能让它在导航栏(z轴)的顶部?或者这是常见的行为?
2)你如何让它从顶部到底部的导航栏被看到?(y轴)
解决方案
您的布局可能适合系统窗口。尽管我在您的示例中没有看到它,但这正是它的作用。也许它也可以设置在其他地方。
系统窗口是系统正在绘制非交互式(在状态栏的情况下)或交互式(在导航栏的情况下)内容的屏幕部分。
大多数情况下,您的应用不需要在状态栏或导航栏下进行绘制,但如果这样做:您需要确保交互元素(如按钮)不会隐藏在它们下方。这就是 android:fitsSystemWindows="true" 属性给你的默认行为:它设置视图的填充以确保内容不会覆盖系统窗口。
这意味着它也将位于底部的导航栏和顶部的系统栏下方。
有一个简单的解决方法。您可以应用窗口插图。
Chris Banes 在那个博客中有一些很好的例子。
snackbarCustomLayout.setOnApplyWindowInsetsListener { view, insets ->
view.updatePadding(bottom = insets.systemWindowInsetBottom)
insets
}
请记住,您可能还需要应用左和/或右插图来处理横向模式。
推荐阅读
- lua - 如何从 Lua 中自 1970 年 1 月 1 日以来经过的秒数中获取日期(月、日、年)?
- json - 如何将所有json值值更改为0 python
- arrays - 无法从 Swift 中的固定大小的 C 数组中读取数据,数据越界
- html - 引导页眉和页脚未在移动设备上显示链接
- java - 为什么 (52 & (1 << 37)) 返回 0?
- javascript - 数组数组中最近的数组
- python - 请求库发送的数据在 python 中是否安全?
- firebase - 如何将数据从 Firestore 映射到列表并转换为对象数据类型
- c# - 在父表单面板中显示用户控件
- gnuplot - 如何将整数转换为字符串 gnuplot