Android Activity as a dialog

后端 未结 10 2391
轮回少年
轮回少年 2020-11-22 02:31

I have an Activity named whereActity which has child dialogs as well. Now, I want to display this activity as a dialog for another activity.

How can I d

相关标签:
10条回答
  • 2020-11-22 03:26

    Some times you can get the Exception which is given below

    Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

    So for resolving you can use simple solution

    add theme of you activity in manifest as dialog for appCompact.

    android:theme="@style/Theme.AppCompat.Dialog"
    

    It can be helpful for somebody.

    0 讨论(0)
  • 2020-11-22 03:27

    Set the theme in your android manifest file.

    <activity android:name=".LoginActivity"
                android:theme="@android:style/Theme.Dialog"/>
    

    And set the dialog state on touch to finish.

    this.setFinishOnTouchOutside(false);
    
    0 讨论(0)
  • 2020-11-22 03:32

    If you want to remove activity header & provide a custom view for the dialog add the following to the activity block of you manifest

    android:theme="@style/Base.Theme.AppCompat.Dialog"
    

    and design your activity_layout with your desired view

    0 讨论(0)
  • 2020-11-22 03:34

    1 - You can use the same activity as both dialog and full screen, dynamically:

    Call setTheme(android.R.style.Theme_Dialog) before calling setContentView(...) and super.oncreate() in your Activity.

    2 - If you don't plan to change the activity theme style you can use

    <activity android:theme="@android:style/Theme.Dialog" />
    

    (as mentioned by @faisal khan)

    0 讨论(0)
提交回复
热议问题