Changing Theme.Holo on Android Manifest.xml file doesn't run on Android

拈花ヽ惹草 提交于 2019-12-23 00:50:49

问题


I am very new to android app development, and have recently hit a wall on the Styling the Action Bar page.

Every time I change the theme to android:theme="@android:style/Theme.Holo.Light" just doesn't allow the program to run on the android, with a message saying "Unfortunately, Program has stopped." every time I try to run it. Weird thing is that it saves perfectly fine on Eclipse with no errors.

Here's my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstappv2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

    <application

        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo"> 

        <activity
            android:name="com.example.myfirstappv2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.myfirstappv2.DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName="com.example.myfirstappv2.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.myfirstappv2.MainActivity" />
        </activity>
    </application>

</manifest>

LogCat:

06-15 21:17:24.748: E/AndroidRuntime(5350): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstappv2/com.example.myfirstappv2.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

回答1:


If your Activity is an ActionBarActivity then you need to use one of the Theme.AppCompat variants (i.e. Theme.AppCompat, Theme.AppCompat.Light, &c).

From the Styling the Action Bar page:

Note: If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme.AppCompat family of styles (rather than the Theme.Holo family, available in API level 11 and higher). In doing so, each style property that you declare must be declared twice: once using the platform's style properties (the android: properties) and once using the style properties included in the Support Library (the appcompat.R.attr properties—the context for these properties is actually your app).

Don't forget about the "add the properties twice" part.



来源:https://stackoverflow.com/questions/24235498/changing-theme-holo-on-android-manifest-xml-file-doesnt-run-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!