Android 弹出对话框Dialog充满屏幕宽度
2015-10-21 15:51
441 查看
项目有时候会用到Dialog充满屏幕有宽度,大多数是从底部显示出来。如下:
style_dialog:
dialog_animation:
enter:
exit:
final View view = LayoutInflater.from(context).inflate(layoutId, null); final Dialog dialog = new Dialog(context, R.style.style_dialog); dialog.setContentView(view); dialog.show(); Window window = dialog.getWindow(); window.setGravity(Gravity.BOTTOM); window.setWindowAnimations(R.style.dialog_animation); window.getDecorView().setPadding(0, 0, 0, 0); WindowManager.LayoutParams lp = window.getAttributes(); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(lp);
style_dialog:
<style name="style_dialog" parent="android:style/Theme.Dialog"> <item name="android:windowBackground">@color/white</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:scrollHorizontally">true</item> </style>
dialog_animation:
<style name="dialog_animation"> <item name="android:windowEnterAnimation">@anim/enter</item> <item name="android:windowExitAnimation">@anim/exit</item> </style>
enter:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="300" /> </set>
exit:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="600" /> </set>
相关文章推荐
- Android 属性动画详解
- RecyclerView妙不可言
- android自定义控件之彩虹加载圆圈
- 学习Android推送功能笔记(2)---极光推送
- Android 高清加载巨图方案 拒绝压缩图片
- 安卓开发学习之012 TextView高级应用
- Android框架基础JNI
- Android_08_服务的使用总结
- Android Studio 入门 Hello World
- Android dp 和 sp的一个小区别
- Material Design之FloatingActionButton的使用
- 一个Android练手工程(ViewPager、Fragment、ListFragment、sqlite)
- AndroidStudio导出jar包
- android4.4插上USB弹出Usb选择界面
- Android判断是否飞行模式已经监听飞行模式
- Android常用组件
- android中的线程机制(二)————SocketCallBack
- AndroidAnnotations框架简单使用方法
- Android 编程下 Touch 事件的分发和消费机制
- Android 项目中执行java的main方法