底部对话框
Posted huyang011
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了底部对话框相关的知识,希望对你有一定的参考价值。
private void showBottomDialog() { final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.show(); Window window = alertDialog.getWindow(); WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.alpha = 0.9f; layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; window.setAttributes(layoutParams); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); //获取屏幕的宽高 window.setLayout((int) (dm.widthPixels * 0.85), ViewGroup.LayoutParams.WRAP_CONTENT); window.setGravity(Gravity.BOTTOM); // window.setGravity(Gravity.CENTER); // 显示的位置 window.setBackgroundDrawable(null); window.setWindowAnimations(R.style.myDialogAnimation); //底部弹出动画 View view = LayoutInflater.from(this).inflate(R.layout.dialog_bottom_profile, null); window.setContentView(view); View unFollowBtn = view.findViewById(R.id.profile_dialog_un_follow); View cancelBtn = view.findViewById(R.id.profile_dialog_cancel); }
<style name="myDialogAnimation" parent="Theme.AppCompat.Dialog"> <item name="android:windowEnterAnimation">@anim/pop_show_anim</item> <item name="android:windowExitAnimation">@anim/pop_hidden_anim</item> </style>
pop_show_anim.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="300" android:fromYDelta="100%" android:toYDelta="0%" android:fromXDelta="0%" android:toXDelta="0%" /> <alpha android:duration="300" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
pop_hidden_anim.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="300" android:fromYDelta="0" android:toYDelta="100%" /> <alpha android:duration="300" android:fromAlpha="1.0" android:toAlpha="1.0" /> </set>
以上是关于底部对话框的主要内容,如果未能解决你的问题,请参考以下文章
BottomNavigationView 后面的片段中的底部工作表
如何将数据从 BottomSheetDialogFragment 返回到父片段
如何使用 JetpackNavigation 组件从 BottomSheetDialogFragment 导航到另一个 Fragment