您需要在此活动中使用 Theme.AppCompat 主题(或后代) [英] You need to use a Theme.AppCompat theme (or descendant) with this activity

查看:50
本文介绍了您需要在此活动中使用 Theme.AppCompat 主题(或后代)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Studio 0.4.5

Android Studio 0.4.5

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

Android documentation for creating custom dialog boxes: http://developer.android.com/guide/topics/ui/dialogs.html

如果您想要自定义对话框,则可以将 Activity 显示为对话框,而不是使用 Dialog API.只需创建一个活动并将其主题设置为 Theme.Holo.Dialog 清单元素:

If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the <activity> manifest element:

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

但是,当我尝试此操作时,出现以下异常:

However, when I tried this I get the following exception:

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

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

I am supporting the following, and I can't using something greater than 10 for the min:

minSdkVersion 10
targetSdkVersion 19

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

In my styles I have the following:

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

在我的清单中,我有这个活动:

And in my manifest I have this for the activity:

 <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>

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

Creating the dialog box like this was something I was hopping to do, as I have already completed the layout.

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

Can anyone tell me how I can get around this problem?

推荐答案

如果你正在使用应用程序上下文,像这样:

If you are using the application context, like this:

final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());

将其更改为这样的活动上下文:

change it to an activity context like this:

final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

这篇关于您需要在此活动中使用 Theme.AppCompat 主题(或后代)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆