在androidjava中实现底层抽屉
我无法在android java中实现底层抽屉,也找不到任何关于其用法的工作示例/教程。您能为使用底部抽屉编写示例代码吗 或者,我尝试使用下拉菜单,但我的应用程序只需要一个底部抽屉在androidjava中实现底层抽屉,java,android,material-design,bottomnavigationview,android-bottomappbar,Java,Android,Material Design,Bottomnavigationview,Android Bottomappbar,我无法在android java中实现底层抽屉,也找不到任何关于其用法的工作示例/教程。您能为使用底部抽屉编写示例代码吗 或者,我尝试使用下拉菜单,但我的应用程序只需要一个底部抽屉 <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/navbottom" android:layout_width="match_parent" a
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navbottom"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_gravity="bottom"
app:menu="@menu/menu_nav"> </com.google.android.material.bottomnavigation.BottomNavigationView>```
下面是我的底部导航视图的代码
这就是它的样子在你添加的屏幕截图中,我看到了一些类似于底部的东西。要获得对话框的这种外观,您可能需要使用BottomSheetDialogFragment,因此下面我将解释如何在您的活动中实现它 1首先,您需要创建一个类,该类将从BottomSheetDialogFragment扩展,并扩展该片段将使用的布局
public class ExampleBottomSheetDialog extends BottomSheetDialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
return inflater.inflate(*R.layout.bottom_sheet_layout*, container, false);
}
}
2然后需要创建*R.layout.bottom_sheet_layout*布局文件,该文件将保存所需的视图,并在需要时为它们提供逻辑
3之后,您可以通过编程设置对话框逻辑。例如,您可以通过按下按钮打开此对话框
Button buttonDialogBottomSheet = findViewById(R.id.btn_sh_dialog);
buttonDialogBottomSheet.setOnClickListener((v) -> {
ExampleBottomSheetDialog bottomSheetDialog = new ExampleBottomSheetDialog();
bottomSheetDialog.show(getSupportFragmentManager(), "simple tag");
});
如果你正在寻找标准的底片,请告诉我,我会更新答案。
上面编写的代码的结果:
事实上,youtube上有很多视频和热门资源中的文章。你能发布一篇吗?我看了很多视频,没有找到一个使用和解释安卓系统底部抽屉的视频。对不起,我最近开始用android编程。你能编辑你的问题并添加你真正想要的吗?你可以使用@BlindKai,只是添加了一个屏幕截图