如何在窗口插图上方制作自定义小吃栏(支持API 14)?

时间:2020-05-10 14:08:23

标签: android android-framelayout android-snackbar windowinsets

我有这个布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/snackbar_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
  <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="top|center" />

  <com.google.android.material.button.MaterialButton
      android:id="@+id/show_snackbar_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:text="@string/show_snackbar"
      android:theme="@style/Theme.GoogleMaterial.DayNight.Bridge" />
</FrameLayout>

我有一个定制的课程:

public final class MySnackbar<AccountT>
    extends BaseTransientBottomBar<MySnackbar<myT>> {

使用

super(findTopMostFrameLayout(parent), content, new MySnackbarAnimation(content));

针对:

 @VisibleForTesting
  protected static ViewGroup findTopMostFrameLayout(View view) {
    FrameLayout fallback = null;
    while (view != null) {
      if (view instanceof FrameLayout) {
        fallback = (FrameLayout) view;
      }
      final ViewParent parent = view.getParent();
      view = parent instanceof View ? (View) parent : null;
    }
    if (fallback != null) {
      return fallback;
    }
    throw new IllegalStateException(
        "Snackbar requires a frameLayout in the view hierarchy tree");
  }

调用"show()"时,它会显示一个具有自定义布局的android快餐栏。

enter image description here

当我显示my_snackbar时,它显示在底部导航栏(z轴)下方。

如何使其位于导航栏上方(z轴和y轴)?

我可以确保该布局的框架布局不是根视图。所以我认为我的布局可以。不?

我看到了这个post,但是我需要支持API 14,并且onApplyWindowInsets()来自Lollipop。

0 个答案:

没有答案
相关问题