The Android Developer documentation describes how to set a Dialog
theme for an Activity
:
Tip: If you want a custom dialog, you can instead display an
Activity
as a dialog instead of using theDialog
APIs. Simply create an activity and set its theme toTheme.Holo.Dialog
in the<activity>
manifest element:
<activity android:theme="@android:style/Theme.Holo.Dialog" >
That's it. The activity now displays in a dialog window instead of fullscreen.
I am trying to do this for an application which uses ActionBarCompat. I have been trying different themes such as ...
android:theme="@android:style/Theme.Dialog"
android:theme="@style/Theme.AppCompat.Base.CompactMenu.Dialog"
android:theme="@style/Theme.AppCompat.CompactMenu.Dialog"
However none of them seems to work since I end up with the same error message:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Just hit the same problem the other day converting from ActionBarSherlock 4.2.0 (which has a special dialog theme removed in later versions, cause it doesn't have much to do with ActionBar really...).
I inspired from it though and came up with a theme for older APIs:
res\values\styles.xml
<style name="AppTheme.Dialog" parent="android:Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@drawable/dialog_full_holo_light</item>
<item name="android:maxWidth">600dp</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
</style>
while using the real Holo dialog theme for later APIs:
res\values-v11\styles.xml
<style name="AppTheme.Dialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
</style>
Finally I had to use a plain Activity to avoid the exception you got, plus another one where ActionBarView checking it's width / height.
You can read my blog post, with a link to the full source code at the end: http://dandar3.blogspot.com/2013/12/actionbarcompat-dialog-activity.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With