2

我是Android新手,似乎有点挂断了......

我正在尝试构建我的第一个 Android 应用程序。该应用程序主要是 Eclipse 为您创建的模板......

我想使用 Holo 主题的基础和默认的黑色背景。我可以通过在 Manifest 中硬编码“@android:style/Theme.Holo”来让它工作(在模拟器上)。但我无法将其从styles.xml 中提取出来。

即使我在 Manifest 中对其进行硬编码,Eclipse 仍然在 Activity 编辑器中显示白色背景,这使得在白色背景上使用白色文本进行设计变得困难......

我确定这是我缺少的一些小东西。请看下面...

在此先感谢彼得

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon48"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="ca.domain.test2.Something"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Holo">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>
4

1 回答 1

5

这是因为您将它放在 res/values/styles.xml 文件中,这意味着它适用于每个 API 版本的应用程序,但最高 10 的版本不支持 Holo 主题。因此,这就是您的文件的外观:

res/values/styles.xml

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Black">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular 
         API-level can go here. -->
</style>

</resources>

res/values-v11/styles.xml

<resources>

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
    <!-- API 11 theme customizations can go here. -->
</style>

</resources>

res/values-v14/styles.xml

<resources>

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo">
    <!-- API 14 theme customizations can go here. -->
</style>

</resources>
于 2013-08-04T21:28:24.007 回答