public class BottomDialog extends Dialog { private Context context; public BottomDialog(Context context) { this(context, R.style.Theme_Light_NoTitle_Dialog); } public BottomDialog(Context context, int themeResId) { super(context, themeResId); this.context = context; } /** * @param view 自定义dialog布局 */ public void showDialog(View view) { Log.d("aode", "showDialog: "+view.getHeight()+"----"+view.getWidth()); Window win = getWindow(); win.getDecorView().setPadding(0, 0, 0, 0); WindowManager.LayoutParams lp = win.getAttributes(); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; win.setAttributes(lp); win.setGravity(Gravity.BOTTOM); win.setWindowAnimations(com.risenb.liangmutian.mypicker.R.style.Animation_Bottom_Rising); setContentView(view); show(); }}
style
<style name="Theme.Light.NoTitle.Dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowFrame">@null</item> </style>从底部弹出 和消失的动画
<style name="Animation.Bottom.Rising" parent="@android:style/Animation"> <item name="android:windowEnterAnimation">@anim/slide_in_bottom</item> <item name="android:windowExitAnimation">@anim/slide_out_bottom</item> </style>两个动画布局<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:interpolator/accelerate_decelerate"> <translate android:duration="@android:integer/config_mediumAnimTime" android:fromYDelta="100%p" android:toYDelta="0" /> <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="0.95" android:toAlpha="1" /> </set><?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="@android:integer/config_mediumAnimTime" android:fromYDelta="0" android:toYDelta="100%p" /> <alpha android:duration="@android:integer/config_mediumAnimTime" android:fromAlpha="1" android:toAlpha="0.95" /> </set>这个一个底部弹出的dialog就完成了 由于android的机型很多,这个dialog也适配华为底部的虚拟键盘
底部弹出dialog模板
最新推荐文章于 2022-10-06 19:50:15 发布