Android 仿苹果底部弹出Dialog
时间:2020-11-07 21:23:58|栏目:Android代码|点击: 次
style文件
<style name="ActionSheetDialogStyle" 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/ActionSheetDialogAnimation</item> </style> <!-- ActionSheet进出动画 --> <style name="ActionSheetDialogAnimation" parent="@android:style/Animation.Dialog"> <item name="android:windowEnterAnimation">@anim/actionsheet_dialog_in</item> <item name="android:windowExitAnimation">@anim/actionsheet_dialog_out</item> </style>
动画文件夹anim两个文件
actionsheet_dialog_in.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:fromYDelta="100%" android:toYDelta="0" />
actionsheet_dialog_out.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:fromYDelta="0" android:toYDelta="100%" />
主Activity应用
private View inflate; private Dialog dialog; public void show(){ dialog = new Dialog(oThis,R.style.ActionSheetDialogStyle); inflate = LayoutInflater.from(oThis).inflate(R.layout.fast_trade_view, null); dialog.setContentView(inflate); Window dialogWindow = dialog.getWindow(); dialogWindow.setGravity( Gravity.BOTTOM); WindowManager.LayoutParams lp = dialogWindow.getAttributes(); lp.y = 20; dialogWindow.setAttributes(lp); dialog.show(); }