在Android Manifest.xml文件更改Theme.Holo不会在Android上运行 [英] Changing Theme.Holo on Android Manifest.xml file doesn't run on Android

查看:769
本文介绍了在Android Manifest.xml文件更改Theme.Holo不会在Android上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的Andr​​oid应用程序开发,并于最近打在的风格化的操作栏页

我每次更改主题为安卓主题=@安卓风格/ Theme.Holo.Light只是不允许在程序上运行机器人,有消息说不幸的是,项目已经停止。每次我尝试运行它。奇怪的是,它保存完美的罚款在Eclipse上没有任何错误。

下面是我的清单文件:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.myfirstappv2
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =11
        机器人:targetSdkVersion =19/>    <应用        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@安卓风格/ Theme.Holo>        <活动
            机器人:名字=com.example.myfirstappv2.MainActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
        <活动
            机器人:名字=com.example.myfirstappv2.DisplayMessageActivity
            机器人:标签=@字符串/ title_activity_display_message
            机器人:parentActivityName =com.example.myfirstappv2.MainActivity>
            &所述;元数据
                机器人:名字=android.support.PARENT_ACTIVITY
                机器人:值=com.example.myfirstappv2.MainActivity/>
        < /活性GT;
    < /用途>< /清单>

LogCat中:

  06-15 21:17:24.748:E / AndroidRuntime(5350):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.myfirstappv2 / com。示例。 myfirstappv2.MainActivity}:java.lang.IllegalStateException:您需要使用Theme.AppCompat主题(或后代)与本次活动。


解决方案

如果您的活动是 ActionBarActivity ,那么你需要使用一个 Theme.AppCompat 变异(即 Theme.AppCompat Theme.AppCompat.Light ,和放大器; C)

风格化的操作栏页:


  

注:如果您使用的是支持库的API操作栏,
  则必须使用(或重写) Theme.AppCompat 家族风格
  (而不是 Theme.Holo 家庭,提供API级别11和
  更高)。这样,你申报每个样式属性必须是
  声明两次:在使用该平台的样式属性(一次
  机器人:属性),一旦使用的样式属性包含在
  支持库(该appcompat.R.attr属性 - 的上下文
  这些特性实际上是对你的应用程序)。


不要忘了添加属性的两倍的一部分。

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.

解决方案

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.

这篇关于在Android Manifest.xml文件更改Theme.Holo不会在Android上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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