试图在Android中使用holo主题无法正常工作

EGH*_*HDK 14 java android android-manifest android-layout

我一直试图在Android中设置一个全息主题,但我无法让它识别它.有任何想法吗?

张贴是我的清单:

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

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:theme="@android:style/Theme.Holo">
        <activity
            android:name=".TestActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

@android:style/Theme.Holo即使我将minSdkVersion更改为11,它也会给我一条红线.任何想法?

更新:

我改了行<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>,以<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>我仍然得到同样的错误.

更新2:

这最终导致我的目标api在清单中正确指定,但在项目属性中没有.很奇怪,但现在还好.

Ale*_*ood 13

Eclipse给你一个错误,因为SDK版本7-10不知道是什么Theme.Holo.您需要为两个平台提供单独的样式,以确保在运行时找到正确的样式.

  1. 在您的res/values/styles.xml文件中,创建以下样式:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="Theme.MyTheme" parent="@android:style/Theme.Black" />
    </resources>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在您的res/values-v11/styles.xml文件中,创建以下样式:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="Theme.MyTheme" parent="@android:style/Theme.Holo" />
    </resources>       
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在您的AndroidManifest.xml文件中,使用以下行作为应用程序的主题:

    android:theme="@style/Theme.MyTheme"
    
    Run Code Online (Sandbox Code Playgroud)


K_A*_*nas 5

你试图使用Holo主题API低于Android 4.0,这就是为什么你可以得到红线:

  1. 使用HoloEverywhere项目
  2. 从ICS源中选择您最想要的Holo Theme所需的资源,并创建自己的自定义主题/样式 https://github.com/android/platform_frameworks_base/tree/master/core/res
  3. 您还可以尝试使用Android Api 7到10的自定义主题和Api 11及更高版本的全息主题,请参阅@Alex Lockwood的答案.