您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
今天就跟大家聊聊有关怎么在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
protected void onCreate(Bundle savedInstanceState) {
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();
}
private void initView() {
View view = View.inflate(this, R.layout.bottom_dialog, null);
ImageView man = (ImageView) view.findViewById(R.id.image_man);
ImageView women = (ImageView) view.findViewById(R.id.image_women);
man.setOnClickListener(this);
women.setOnClickListener(this);
bsd1 = new BottomSheetDialog(this);
bsd1.setContentView(view);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.toolbar_back:
finish();
break;
case R.id.btn_bsd1:
bsd1.show();
break;
case R.id.image_man:
ToastUtil.show("男");
bsd1.dismiss();
break;
case R.id.image_women:
ToastUtil.show("女");
bsd1.dismiss();
break;
}
}看完上述内容,你们对怎么在Android中使用BottomSheetDialog实现一个底部对话框有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。