将加载动画添加到kotlin中的自定义对话框

时间:2018-01-25 05:15:28

标签: android kotlin android-alertdialog

我想将加载动画添加到自定义对话框中,我能够在java中执行此操作但我有问题在kotlin中执行相同操作它会给我以下错误

STRING

以下是我在kotlin

中创建对话框的代码
E/AndroidRuntime: FATAL EXCEPTION: main
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:229)
at com.android.internal.app.AlertController.installContent(AlertController.java:234)
at android.app.AlertDialog.onCreate(AlertDialog.java:337)
at android.app.Dialog.dispatchOnCreate(Dialog.java:355)
at android.app.Dialog.show(Dialog.java:260)
at com.autodroid.demo.MainActivity.show(MainActivity.kt:66)
at com.autodroid.demo.MainActivity$onCreate$1.onClick(MainActivity.kt:32)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)

任何指针都将受到赞赏,在此先感谢:)

1 个答案:

答案 0 :(得分:1)

<强> style.xml

<style name="yourCustomDialog" parent="@android:style/Theme.Dialog">
         <item name="android:windowAnimationStyle">@style/yourCustomDialogAnimation</item>
     </style>

     <style name="yourCustomDialogAnimation">
        <item name="android:windowEnterAnimation">@anim/slide_down</item>
        <item name="android:windowExitAnimation">@anim/slide_up</item>
     </style>

 </resources>

如何在kotlin代码中使用

val dialogBuilder = AlertDialog.Builder(activity,R.style.yourCustomDialog)