怎么在Android中使用BottomSheetDialog实现一个底部对话框
作者
今天就跟大家聊聊有关怎么在Android中使用BottomSheetDialog实现一个底部对话框,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
使用方法
BottomSheetDialog来自design兼容包,使用需要添加依赖。android studio 添加依赖如下:
dependencies{ compile‘com.android.support:design:23.2.0+‘ }
1.XML中添加布局文件
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="2"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> <ImageView android:id="@+id/image_man" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:selectableItemBackground" android:gravity="center" android:padding="10dp" android:src="@drawable/man"/> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> <ImageView android:id="@+id/image_women" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:selectableItemBackground" android:gravity="center" android:padding="10dp" android:src="@drawable/women"/> </RelativeLayout> </LinearLayout>
2.在代码中使用
@Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_play_bottom_sheet_dialog); showContentView(); bindingView.bottomsheet.textviewTitle.setText("BottomSheetDialog"); bindingView.bottomsheet.toolbarBack.setOnClickListener(this); bindingView.btnBsd1.setOnClickListener(this); initView(); } privatevoidinitView(){ Viewview=View.inflate(this,R.layout.bottom_dialog,null); ImageViewman=(ImageView)view.findViewById(R.id.image_man); ImageViewwomen=(ImageView)view.findViewById(R.id.image_women); man.setOnClickListener(this); women.setOnClickListener(this); bsd1=newBottomSheetDialog(this); bsd1.setContentView(view); } @Override publicvoidonClick(Viewv){ switch(v.getId()){ caseR.id.toolbar_back: finish(); break; caseR.id.btn_bsd1: bsd1.show(); break; caseR.id.image_man: ToastUtil.show("男"); bsd1.dismiss(); break; caseR.id.image_women: ToastUtil.show("女"); bsd1.dismiss(); break; } }
看完上述内容,你们对怎么在Android中使用BottomSheetDialog实现一个底部对话框有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注恰卡编程网行业资讯频道,感谢大家的支持。
目录
推荐阅读
-
怎么使用Android基准配置文件Baseline Profile方案提升启动速度
-
HTML5如何实现禁止android视频另存为
-
学java好还是学php好?
-
Android如何实现多点触控功能
-
android怎么实现多点触摸应用
-
Android怎么实现手势划定区域裁剪图片
-
android怎么实现简单的矩形裁剪框
-
Android单选多选按钮怎么使用
-
Android中如何利用oncreate获取控件高度或宽度
Android中如何利用oncreate获取控件高度或宽度本篇内容...
-
Android中怎么使用onSaveInstanceState()方法
Android中怎么使用onSaveInstanceState()方法...
0 条评论
本站已关闭游客评论,请登录或者注册后再评论吧~