设置底部弹出菜单
2018-03-23 14:39
155 查看
一、步骤
1、引用依赖implementation 'com.android.support:design:26.1.0'
2、创建Layout布局
bottomdailog.xml
3、创建BottomSheetDialog
BottomSheetDialog dialog = new BottomSheetDialog(this);4、引入自定View
View dialogView = LayoutInflater.from(this).inflate(R.layout.bottomdailog, null);
5、引用控件
findViewById(R.id.more_login_exception)6、控件的点击事件处理
.setOnClickListener(this)7、View添加到BottomSheetDialog
dialog.setContentView(dialogView);8、显示.show()
dialog.show();
二、完整代码
1、页面布局<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/more_login_exception"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="登录异常"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@color/colorHint" />
<TextView
android:id="@+id/more_contact_customer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="联系客服"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/colorHint" />
<TextView
android:id="@+id/tv_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="关闭"
android:textSize="20sp" />
</LinearLayout>
2、方法调用
public void showDialog() {
final BottomSheetDialog dialog = new BottomSheetDialog(this);
View dialogView = LayoutInflater.from(this).inflate(R.layout.bottomdailog, null);
TextView more_login_exception = dialogView.findViewById(R.id.more_login_exception);
TextView more_contact_customer = dialogView.findViewById(R.id.more_contact_customer);
TextView tv_cancel = dialogView.findViewById(R.id.tv_cancel);
more_login_exception.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(LoginActivity.this, "登录异常", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
more_contact_customer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(LoginActivity.this, "联系客服", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
tv_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.setContentView(dialogView);
dialog.show();
}
相关文章推荐
- 设置toolbar中弹出的menu菜单在toolbar的底部(下面)显示
- android Activity实现从底部弹出或滑出选择菜单或窗口
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 使用CoordinatorLayout实现底部弹出菜单
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 实现底部导航栏中间凸起,(点击中间凸出按钮弹出菜单)
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- ExpandableButtonMenu |底部弹出菜单
- Android仿网易严选底部弹出菜单效果
- 同时弹出顶部和底部的菜单
- android Activity实现从底部弹出或滑出选择菜单或窗口
- Android DialogFragment底部弹出菜单
- Android 长按Listview 每个item底部弹出菜单
- 自定义底部菜单,当弹出输入法时,底部菜单被挤到输入法上面
- 右键弹出菜单和快捷键的设置
- 安卓开发:自定义PopupWindow,实现模仿iOS底部弹出菜单
- popupwindo translate animation 从底部弹出 动画设置