Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

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

Android Studio 0.4.5

(Android Studio 0.4.5)

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

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

If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs.

(如果需要自定义对话框,则可以将“活动”显示为对话框,而不是使用Dialog API。)

Simply create an activity and set its theme to Theme.Holo.Dialog in the <activity> manifest element:

(只需创建一个活动并将其主题设置为<activity>清单元素中的Theme.Holo.Dialog即可:)

<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

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

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

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?

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

  ask by ant2009 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The reason you are having this problem is because the activity you are trying to apply the dialog theme to is extending ActionBarActivity which requires the AppCompat theme to be applied.

(您遇到此问题的原因是,您尝试将对话框主题应用到的活动正在扩展ActionBarActivity ,而这需要应用AppCompat主题。)

Update : Extending AppCompatActivity would also have this problem

(更新 :扩展AppCompatActivity也会有此问题)

In this case, change the Java inheritance from ActionBarActivity to Activity and leave the dialog theme in the manifest as it is, a non Theme.AppCompat value

(在这种情况下,请将Java继承从ActionBarActivity更改为Activity ,并将对话框主题原样保留在清单中(非Theme.AppCompat值))


The general rule is that if you want your code to support older versions of Android, it should have the AppCompat theme and the java code should extend AppCompatActivity .

(一般规则是,如果您希望代码支持旧版本的Android,则它应具有AppCompat主题,而Java代码应扩展AppCompatActivity 。)

If you have *an activity that doesn't need this support, such as you only care about the latest versions and features of Android, you can apply any theme to it but the java code must extend plain old Activity .

(如果您有不需要此支持的活动,例如您只关心Android的最新版本和功能,则可以对其应用任何主题,但是Java代码必须扩展普通的旧Activity 。)


NOTE: When change from AppCompatActivity (or a subclass, ActionBarActivity ), to Activity , must also change the various calls with "support" to the corresponding call without "support".

(注意:从AppCompatActivity (或子类ActionBarActivity )更改为Activity ,还必须将带有“ support”的各种调用更改为没有 “ support”的相应调用。)

So, instead of getSupportFragmentManager , call getFragmentManager .

(因此,调用getFragmentManager代替getSupportFragmentManager 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...