gpt4 book ai didi

android - 如何在 Bottombar 上方显示 Snackbar?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:45:15 24 4
gpt4 key购买 nike

我正在使用 roughike 的 BottomBar 2.0:https://github.com/roughike/BottomBar/

当我显示 SnackBar 时,它会显示在 BottomBar 本身上。

我希望它绘制在 BottomBar 之上。

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/here"
android:background="#fff">

<FrameLayout
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomBar">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Three Buttons Bar"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="@color/colorPrimary"
android:textSize="35sp" />

</FrameLayout>

<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />
</RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

MainActivity.java:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(int tabId) {
switch (tabId) {
case R.id.recent_item:
Snackbar.make(findViewById(R.id.main_activity), "Recent Item Selected", Snackbar.LENGTH_LONG).show();
break;
case R.id.favorite_item:
Snackbar.make(findViewById(R.id.main_activity), "Favorite Item Selected", Snackbar.LENGTH_LONG).show();
break;
case R.id.location_item:
Snackbar.make(findViewById(R.id.main_activity), "Location Item Selected", Snackbar.LENGTH_LONG).show();
break;
}
}
});
}
}

截图:

BottomBar Only BottomBar hidden when SnackBar appears

布局文件有问题吗??
我错过了什么??

我还检查了这个:Move snackbar above the bottom bar , 但它没有帮助..

编辑:

我试过了 as Abtin said :

Snackbar.make(bottomBar, "Location Item Selected", Snackbar.LENGTH_LONG).show();

<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs"
app:bb_behavior="underNavbar"/>

现在变成了这样:

Bottom Bar with extra space below That space filled by Snackbar

如您所见,当我设置 app:bb_behavior="underNavbar" 时,BottomBar 下方有这个未使用的空间,这不是我想要的..

最佳答案

有了新的 Material 设计,Snackbars 有了新的外观..你可以用这行代码在 BottomBar 上方显示 snackbar:

Snackbar snackbar = Snackbar.make(parentView, text, duration);
snackbar.setAnchorView(bottomBar);

这将完成工作。

关于android - 如何在 Bottombar 上方显示 Snackbar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40092618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com