怎么在Android中使用BottomSheetDialog实现一个底部对话框

今天就跟大家聊聊有关怎么在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实现一个底部对话框有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注恰卡编程网行业资讯频道,感谢大家的支持。

发布于 2021-04-08 13:37:53
收藏
分享
海报
0 条评论
173
上一篇:如何在Vue.js项目中添加组件 下一篇:如何在canvas中使用环形倒计时组件
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码