Android Studio 0.4.5

用于创建自定义对话框的Android文档:http://developer.android.com/guide/topics/ui/dialogs.html

如果您想要一个自定义对话框,您可以将活动显示为对话框,而不是使用对话框api。简单地创建一个活动,并将其主题设置为theme . holo . dialog in <activity> manifest元素:

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

然而,当我尝试这样做时,我得到以下异常:

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

我支持以下,我不能使用大于10的最小值:

minSdkVersion 10
targetSdkVersion 19

在我的风格中,我有以下几点:

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

在我的清单上,我有这样的活动:

 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:theme="@android:style/Theme.Holo.Light.Dialog"
            android:name="com.ssd.register.Dialog_update"
            android:label="@string/title_activity_dialog_update" >
        </activity>

创建这样的对话框是我一直在做的事情,因为我已经完成了布局。

谁能告诉我如何解决这个问题?


当前回答

检查是否向Dialog传递了正确的上下文。这发生在我身上,然后我意识到我正在启动AlertDialog。使用applicationContext而不是Activity上下文的构建器。

其他回答

你之所以这么做,是因为你想在之前的sdk版本21的主题样式中应用材质设计。ActionBarActivity需要AppThemeso,如果你也想防止你自己的自定义关于你的AppTheme,只是你必须改变你的样式。xml(之前的sdk 21),这样,可以继承一个App Compat主题。

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">

:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

在MaterialAlertDialogBuilder中使用“this”而不使用“applicationContext”

MaterialAlertDialogBuilder(this).show()

更改清单文件

/ Theme.Holo @android:风格。Light //应用中提到的任何一个

to

@android:主题=“@style /主题。AppCompat”

这让我工作了,希望能有所帮助

如果有人在运行Android 12启动画面时看到这个错误,请遵循以下简单的步骤

The app theme in values/themes.xml and values-night/themes.xml should have Theme.AppCompat as the parent theme. <style name="Theme.Ace" parent="Theme.AppCompat.DayNight.NoActionBar"> Use this theme in postSplashScreenTheme for the splash screen theme <style name="Theme.App.Starting" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/orange_900</item> <item name="windowSplashScreenAnimatedIcon">@drawable/ic_help_outline</item> <item name="windowSplashScreenAnimationDuration">2000</item> <item name="postSplashScreenTheme">@style/Theme.Ace</item> Remove any theme from the starting activity and use Theme.App.Starting as an application theme <application... android:theme="@style/Theme.App.Starting">

不要忘记在VCS本地历史记录恢复后清理项目