标签:
其实很简单:
只是把activity的theme设置成dilog形式的:
<activity android:name=".ActivityPackage.DatePickerActivity"
android:theme="@style/DefaultFullScreenDialogAnimation">
</activity>
下面是DefaultFullScreenDialogAnimation:
<style name="DefaultFullScreenDialogAnimation" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@style/DialogIOSAnimation</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:windowBackground">@android:color/transparent</item>//将背景设置成透明的
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowCloseOnTouchOutside">true</item>//设置窗体外面允不允许点击
</style>
下面是DialogIOSAnimation:
<style name="DialogIOSAnimation" parent="@android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/dialog_ios_scale_in</item>
<item name="android:windowExitAnimation">@anim/dialog_ios_scale_out</item>
</style>
下面是出现的效果dialog_ios_scale_in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200" >
<scale
android:interpolator="@android:anim/decelerate_interpolator"
android:fromXScale="1.2"
android:toXScale="1.0"
android:fromYScale="1.2"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
/>
<alpha
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
/>
</set>
下面是淡出效果dialog_ios_scale_out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200" >
<scale
android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="1.2"
android:fromYScale="1.0"
android:toYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
/>
<alpha
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.5"
android:toAlpha="0.0"
/>
</set>
这样就是先了把activity的风格转换成了dialog的风格,但是如果你还想让这个activity的宽度与屏幕一样大小的话,还需要在activity里面进行设置:
/*设置dialog的宽与屏幕想等*/
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
getWindow().setAttributes(lp);
这里是一种自定义的style风格,具体是需要什么样的风格由自己去设置,这里只是给予参考。
标签:
原文地址:http://www.cnblogs.com/xulibing/p/5376477.html