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>

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

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


当前回答

我也有这个问题,我做了什么来解决它,仍然使用Holo主题是采取以下步骤:

首先我替换了这个导入:

import android.support.v7.app.AppCompatActivity;

比如这个:

import android.app.Activity;

然后将我的扩展名从:

public class MyClass extends AppCompatActivity {//...

:

public class MyClass extends Activity {//...

同时还要更改这个导入:

import android.support.v7.app.AlertDialog;

对于这一点:

import android.app.AlertDialog;

然后你可以在活动级别的清单中使用你的主题标签:

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

最后,(除非你的项目中有其他类必须使用v7 appCompat),你可以清理并重新构建你的项目,或者在应用程序级别删除gradle构建文件中的这个条目:

compile 'com.android.support:appcompat-v7:23.2.1'

如果你的项目中有其他类必须使用v7 appCompat,那么只需清理并重新构建项目。

其他回答

最小SDK为10。ActionBar从api级别11可用。因此,对于10,您将使用来自支持库的AppCompat,您需要使用Theme。AppCompat或其后代。

Use

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

或者如果你不想在顶部的操作栏

android:theme="@style/Theme.AppCompat.NoActionBar">

更多信息@

http://developer.android.com/guide/topics/ui/actionbar.html

编辑:

我可能看错了行动报告。

似乎op想要一个带有活动主题的对话框。正如Bobbake4所建议的,扩展Activity而不是ActionBarActivity。

也可以看看下面链接中的@ Dialog Attributes

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4_r1/frameworks/base/core/res/res/values/themes.xml/

在我的例子中,我使用了一个名为“FullScreenTheme”的样式,尽管它似乎是正确定义的(它是Theme.AppCompat的后代),但它并不能工作。

我终于意识到,我正在使用一个AAR库,内部也定义了一个名为“FullScreenTheme”的风格,它不是Theme.AppCompat的后代。名字的冲突导致了这个问题。

通过重命名我自己的样式名称来修复它,现在Android正在使用正确的样式。

对于这个错误,有很多解决方案。

你应该使用Activity或FragmentActivity而不是ActionbarActivity或AppCompatActivity 如果你想使用ActionbarActivity或AppCompatActivity,你应该把styles.xml Theme.Holo.xxxx改成Theme.AppCompat.Light(如果需要的话添加到DarkActionbar)

如果你不需要关于动作栏或AppCompat的高级属性,你不需要使用动作栏或AppCompat。

在我的例子中,我用ApplicationContext来膨胀一个视图。当你使用ApplicationContext时,theme/style不会被应用,所以尽管有theme . context。Appcompat在我的风格,它没有应用,导致这个异常。更多细节:当膨胀器与ApplicationContext一起使用时,主题/样式不应用

注意:我本来打算用这个作为答案,但进一步的测试显示,从命令行使用maven构建时仍然会失败,所以我不得不对它进行编辑,使之成为一个问题!: - (

在我的情况下,当我得到这个错误时,我已经在使用AppCompat主题和错误没有多大意义。

我正在构思我的安卓系统。我已经依赖于apklib和jar版本的应用程序compat,因此:

    <!-- See https://github.com/mosabua/maven-android-sdk-deployer -->
        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v7-appcompat</artifactId>
            <version>${compatibility.version}</version>
            <type>apklib</type>
        </dependency>

        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v7-appcompat</artifactId>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v7</artifactId>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v4</artifactId>
        </dependency>

现在,当我导入maven项目并从IntelliJ构建和运行时,一切都好了。

但是当我使用maven从命令行构建、部署和运行时,我仍然会得到这个异常。