首页 > 系统 > Android > 正文

Android 底部弹出Dialog

2019-11-08 00:23:17
字体:
来源:转载
供稿:网友
项目开发中经常遇到使用底部弹出Dialog 例如选择图片上传时的 本地图库 和 拍照  还有支付时的支付方式选择  下面是我写的一个支付方式选择的底部弹出 Dialog  不足之处请指出 谢谢初始化
PRivate void initDialog() {        dialog = new Dialog(this, R.style.recharge_pay_dialog);        //填充对话框的布局        View rootView = LayoutInflater.from(this).inflate(R.layout.dialog_pay, null);        //将布局设置给Dialog        dialog.setContentView(rootView);        //获取当前窗体        Window dialogWindow = dialog.getWindow();        //设置Dialog从窗体底部弹出        dialogWindow.setGravity(Gravity.BOTTOM);        //获得窗体的属性        WindowManager.LayoutParams lp = dialogWindow.getAttributes();        //窗体dialog 布局宽度设为Matc_Parent        lp.width = AbsListView.LayoutParams.MATCH_PARENT;        lp.y = 0;//设置Dialog距离底部的距离        //将属性设置给窗体        dialogWindow.setAttributes(lp);        dialog.show();//显示对话框    }布局文件
<?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:background="@color/white"    android:orientation="vertical">    <RelativeLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:layout_width="wrap_content"            android:layout_height="@dimen/dp_40"            android:layout_centerInParent="true"            android:gravity="center"            android:text="@string/recharge_pay_detail"            android:textColor="@color/black"            android:textSize="@dimen/dp_18" />        <ImageView            android:layout_width="@dimen/dp_40"            android:layout_height="@dimen/dp_40"            android:layout_alignParentRight="true"            android:scaleType="center"            android:src="@drawable/icon_right" />    </RelativeLayout>    <View style="@style/recharge_line_gray" />    <TextView        style="@style/recharge_text_gray"        android:text="@string/recharge_please_choose" />    <View style="@style/recharge_line_margin_gray" />    <RelativeLayout        android:id="@+id/dialog_zhifubao"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <ImageView            android:id="@+id/recharge_left1"            android:layout_width="@dimen/dp_45"            android:layout_height="@dimen/dp_45"            android:layout_alignParentLeft="true"            android:layout_marginLeft="@dimen/dp_25" />        <TextView            android:layout_toRightOf="@+id/recharge_left1"            style="@style/recharge_text_gray"            android:text="@string/recharge_zhifubao" />        <ImageView            android:id="@+id/recharge_zhifubao_cb"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentRight="true"            android:layout_centerVertical="true"            android:layout_marginRight="@dimen/dp_25"            android:src="@drawable/cb_btn_checked" />    </RelativeLayout>    <View style="@style/recharge_line_margin_gray" />    <RelativeLayout        android:id="@+id/dialog_wechat"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <ImageView            android:id="@+id/recharge_left2"            android:layout_width="@dimen/dp_45"            android:layout_height="@dimen/dp_45"            android:layout_alignParentLeft="true"            android:layout_marginLeft="@dimen/dp_25" />        <TextView            android:layout_toRightOf="@+id/recharge_left2"            style="@style/recharge_text_gray"            android:text="@string/recharge_wechat" />        <ImageView            android:id="@+id/recharge_wechat_cb"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_alignParentRight="true"            android:layout_centerVertical="true"            android:layout_marginRight="@dimen/dp_25"            android:src="@drawable/cb_btn_checked"            android:visibility="gone" />    </RelativeLayout>    <View style="@style/recharge_line_margin_gray" />    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="right"        android:gravity="center_vertical"        android:minWidth="@dimen/dp_130"        android:paddingBottom="@dimen/dp_5"        android:paddingTop="@dimen/dp_5">        <TextView            style="@style/recharge_text_gray"            android:text="@string/recharge_need_pay" />        <TextView            android:id="@+id/recharge_num"            android:layout_width="wrap_content"            android:layout_height="@dimen/dp_45"            android:layout_marginLeft="@dimen/dp_8"            android:layout_marginRight="@dimen/dp_25"            android:gravity="center"            android:text="¥600.00"            android:textColor="@color/colorPrimary"            android:textSize="@dimen/text_size_18" />    </LinearLayout>    <TextView        android:id="@+id/dialog_confirm_pay"        android:layout_width="match_parent"        android:layout_height="50dp"        android:background="@color/colorPrimary"        android:gravity="center"        android:text="@string/recharge_confirm_pay"        android:textColor="@color/white"        android:textSize="@dimen/text_size_16" /></LinearLayout>Dialog Style
<!-- 支付方式Dialog 样式 --><style name="recharge_pay_dialog" parent="@android:style/Theme.Dialog">    <!-- 背景透明 -->    <item name="android:windowBackground">@android:color/transparent</item>    <item name="android:windowContentOverlay">@null</item>    <!-- 浮于Activity之上 -->    <item name="android:windowIsFloating">true</item>    <!-- 边框 -->    <item name="android:windowFrame">@null</item>    <!-- Dialog以外的区域模糊效果 -->    <item name="android:backgroundDimEnabled">true</item>    <!-- 无标题 -->    <item name="android:windowNoTitle">true</item>    <!-- 半透明 -->    <item name="android:windowIsTranslucent">true</item>    <!-- Dialog进入及退出动画 -->    <item name="android:windowAnimationStyle">@style/racharge_dialog_animation</item></style>Animtation style
<style name="racharge_dialog_animation" parent="@android:style/Animation.Dialog">    <item name="android:windowEnterAnimation">@anim/dialog_enter</item>    <item name="android:windowExitAnimation">@anim/dialog_exit</item></style>animation set
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:fromYDelta="100%p"  android:duration="400"/></set><?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:toYDelta="100%p"      android:duration="400"/></set>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表