我可以将 snackbar 锚定到 Android 本机底部导航栏吗?

Can I anchor a snackbar to Android native bottom navigation bar?

我想将快餐栏锚定到 Android 本机底部导航栏。

正如我看到的文档:

Anchoring a Snackbar By default, Snackbars will be anchored to the bottom edge of their parent view. However, you can use the Snackbar#setAnchorView method to make a Snackbar appear above a specific view within your layout, e.g., a FloatingActionButton. This is especially helpful if you would like to place a Snackbar above navigational elements at the bottom of the screen, such as a BottomAppBar or BottomNavigationView.

我看到这个 post 如何获得 Android 本机底部导航栏。

int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
        return id > 0 && resources.getBoolean(id);

但是,它是否只是我可以获得的布尔值而没有视图本身的 id?

据我了解,您需要将小吃栏放在底部导航上方,您需要做的就是:

val bottomNavigation: BottomNavigationView = findViewById(R.id.bottom_navigation)
Snackbar.make(it, "Hello World", Snackbar.LENGTH_LONG).setAnchorView(bottomNavigation).show()

注意:有关 Snackbars 和 Android 总体设计的不错文档。