我是新手程序员,我有禁用对话框动画(淡入和淡出)的问题.
我尝试使用空样式并通过更改设置它
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
成
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(),R.style.NoAnimation));
对话框的背景变为黑色,正面和否定按钮变为< 2.1 - 4.0)android风格,但淡入和淡出动画效果仍然... 我的风格:
<style name="DialogNoAnimation"> <item name="android:windowEnterAnimation">@anim/enter</item> <item name="android:windowExitAnimation">@anim/exit</item> </style> <style name="NoAnimation" parent="@android:style/Theme.Dialog"> <item name="android:windowAnimationStyle">@style/DialogNoAnimation</item> </style>
任何想法如何消除这个动画?
解决方法
终于成功了!
RES /动画/ enter.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_shortAnimTime"/>
RES /动画/ exit.xml
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_shortAnimTime"/>
RES /值/ styles.xml
<style name="DialogNoAnimation"> <item name="android:windowEnterAnimation">@anim/enter</item> <item name="android:windowExitAnimation">@anim/exit</item> </style>
SRC / [dialog_Box_class]的.java
@Override public void onStart() { super.onStart(); if (getDialog() == null) return; getDialog().getWindow().setWindowAnimations(R.style.DialogNoAnimation); }