Android编程入门--底部Dialog弹窗

知是行的主意,行是知的功夫。这篇文章主要讲述Android编程入门--底部Dialog弹窗相关的知识,希望能为你提供帮助。
参考博客:Android实现底部对话框BottomDialog
dialog_bottom

< ?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="@android:color/white" android:orientation="horizontal"> < LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> < TextView android:id="@+id/tv_ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:clickable="true" android:drawableLeft="@drawable/ic_check_666666_24dp" android:drawablePadding="16dp" android:gravity="center_horizontal" android:padding="16dp" android:text="@string/dialog_ok" android:textColor="#666666" android:textSize="14sp" /> < /LinearLayout> < LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> < TextView android:id="@+id/tv_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:clickable="true" android:drawableLeft="@drawable/ic_close_666666_24dp" android:drawablePadding="16dp" android:gravity="center_horizontal" android:padding="16dp" android:text="@string/dialog_cancel" android:textColor="#666666" android:textSize="14sp" /> < /LinearLayout> < /LinearLayout>

 
style
< resources> < style name="BottomDialog" parent="Theme.AppCompat.Light.Dialog"> < item name="android:windowNoTitle"> true< /item> < item name="android:windowBackground"> @android:color/transparent< /item> < /style> < style name="BottomDialog.Animation" parent="Animation.AppCompat.Dialog"> < item name="android:windowEnterAnimation"> @anim/translate_dialog_in< /item> < item name="android:windowExitAnimation"> @anim/translate_dialog_out< /item> < /style> < /resources>

anim
translate_dialog_in
< ?xml version="1.0" encoding="utf-8"?> < translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromXDelta="0" android:fromYDelta="100%" android:toXDelta="0" android:toYDelta="0"> < /translate>

translate_dialog_out
< ?xml version="1.0" encoding="utf-8"?> < translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="0" android:toYDelta="100%"> < /translate>

代码如下
@OnClick(R.id.log_out_layout) public void onLogOutClicked() { final Dialog mDialog = new Dialog(this.getActivity(), R.style.BottomDialog); View contentView = LayoutInflater.from(this.getActivity()).inflate(R.layout.dialog_bottom, null); mDialog.setContentView(contentView); ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams(); layoutParams.width = getResources().getDisplayMetrics().widthPixels; contentView.setLayoutParams(layoutParams); mDialog.getWindow().setGravity(Gravity.BOTTOM); mDialog.setCanceledOnTouchOutside(true); mDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation); mDialog.show(); TextView tvOk = (TextView) contentView.findViewById(R.id.tv_ok); tvOk.setOnClickListener(new View.OnClickListener() {@Override public void onClick(View v) { System.exit(0); //系统退出 } }); TextView tvCancel = (TextView) contentView.findViewById(R.id.tv_cancel); tvCancel.setOnClickListener(new View.OnClickListener() {@Override public void onClick(View v) { mDialog.cancel(); } }); }

【Android编程入门--底部Dialog弹窗】 

    推荐阅读