Google MaterialDesign_BottomSheetDialog简单用法
2016-08-16 21:49
579 查看
谷歌官方文档里叫BottomSheet(底部动作条),不过真心没有,值找到了BottomSheetDialog(底部表格式对话框,以下简称BSD)。具体效果就是从屏幕底部滑上来一个菜单,而且能一直向上滑动,是一个列表形式。这个菜单是通过适配器填充的,我最近一直用recyclerview来代替其他列表,所以今天亦是如此;这个BSD能满足更多需求,因为它是通过适配器填充的。运行了代码就知道了!
看一下效果图(形式一样不过是盗图,我一直没研究咋录制gif)
一 、 list.xml
这是列表中每一个item,其实按照我本意,里面的textview其实是所有的,所以你可以只放一个textview!
二 、 外置一个含有recyclerview的xml文件
三、activity中的代码 可以在任何事件中调用如下函数
看一下效果图(形式一样不过是盗图,我一直没研究咋录制gif)
一 、 list.xml
这是列表中每一个item,其实按照我本意,里面的textview其实是所有的,所以你可以只放一个textview!
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="vertical"> <TextView android:id="@+id/textt" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="0" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="s" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="m" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="l" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="xl" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="XXL" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="XXXL" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="不好意思没更肥的了" /> </LinearLayout>
二 、 外置一个含有recyclerview的xml文件
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/recyclerview" android:layout_width="match_parent" android:layout_height="match_parent" tools:showIn="@layout/activity_main2" /><!--用于底部动作条-->
三、activity中的代码 可以在任何事件中调用如下函数
private void openBottom() { RecyclerView recyclerView = (RecyclerView) LayoutInflater.from(this).inflate(R.layout.recyclerview, null); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setLayoutManager(new GridLayoutManager(this, 3)); BottomSheetAdapter adapter = new BottomSheetAdapter(); recyclerView.setAdapter(adapter); final BottomSheetDialog dialog = new BottomSheetDialog(this); dialog.setContentView(recyclerView); dialog.show(); adapter.setOnItemClickListener(new BottomSheetAdapter.OnBottomItemClickListener() { @Override public void onItemClick(int position, String text) { showToast(text); dialog.dismiss(); } }); }
相关文章推荐
- BottomSheetDialog的简单实用
- BottomSheetBehavior、BottomSheetDialog和BottomSheetDialogFragment的用法
- SaveFileDialog的简单用法
- C#的OpenFileDialog的简单用法
- android学习总结(16.09.08)AlertDialog的简单用法
- BottomSheetDialog的使用
- 简单实用的google用法
- AlertDialog的超简单用法
- 解决使用BottomSheetDialog时状态栏变黑的问题
- 解决使用BottomSheetDialog时状态栏变黑的问题
- Android Material Design之BottomSheetDialog
- window.showModalDialog()的简单用法
- Material Design系列,Behavior之BottomSheetBehavior与BottomSheetDialog
- <AlertDialog>的简单用法与功能
- 解决使用BottomSheetDialog时状态栏变黑的问题
- Android BottomSheetDialog透明问题的解决办法
- DatePickerDialog 简单用法
- 动态获取程序的版本名称的方法以及dialog的简单用法以及两种上下文的区别
- BottomSheetDialog
- 简单粗暴打造BottomSheet效果