Android 如何为特定项目设置主题

Android 如何为特定项目设置主题,android,Android,我想设定光环主题。数字选择器和显示它的活动具有不同的主题。我在xml属性中完成了这项工作,并将halo主题赋予数字选择器。但它不起作用。请帮忙 我的。。。。 style.xml <?xml version="1.0" encoding="utf-8"?> <resources> <style name="Animations" /> <style name="Animations.GrowFromBottom">

我想设定光环主题。数字选择器和显示它的活动具有不同的主题。我在xml属性中完成了这项工作,并将halo主题赋予数字选择器。但它不起作用。请帮忙

我的。。。。 style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Animations" />

    <style name="Animations.GrowFromBottom">
        <item name="@android:windowEnterAnimation">@anim/grow_from_bottom</item>
        <item name="@android:windowExitAnimation">@anim/shrink_from_top</item>
    </style>

    <style name="Animations.GrowFromTop">
        <item name="@android:windowEnterAnimation">@anim/grow_from_top</item>
        <item name="@android:windowExitAnimation">@anim/shrink_from_bottom</item>
    </style>

    <style name="Animations.PopDownMenu">
        <item name="@android:windowEnterAnimation">@anim/grow_from_topleft_to_bottomright</item>
        <item name="@android:windowExitAnimation">@anim/shrink_from_bottomright_to_topleft</item>
    </style>

    <style name="AndroDev" parent="@android:style/Theme.Holo.Light"></style>

</resources>

@从底部动画/生长
@动画/从顶部收缩
@动画/从顶部生长
@动画/从底部收缩
@动画/从左上到右下生长
@动画/从右下到左上收缩
我的清单文件

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

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

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

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

</manifest>

我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <NumberPicker
        android:id="@+id/numberPicker"
        style="@style/AndroDev"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#ffffff"
        android:orientation="horizontal" />

</LinearLayout>

用于活动
  • 要从清单文件执行此操作,请在活动标记中追加
    android:theme=“@android:style/theme.Holo.Light”
  • 要在活动类中执行此操作,可以通过
    super.setTheme(android.R.style.Theme.Holo.Light)
用于数字选择器
通过res/values/style.xml创建自定义样式

<?xml version.....>
<resources>
<style name="AndroDev" parent="@android:style/Theme.Holo.Light">
    <item name="android:background">#ffffff</item>
</style>
</resources>

#ffffff
然后在定义数字选择器视图的xml中使用此选项:

<NumberPickerView style:"@style/AndroDev" ....>

我举了全息光主题的例子。您可以更改为任何您想要的。

活动
  • 要从清单文件执行此操作,请在活动标记中追加
    android:theme=“@android:style/theme.Holo.Light”
  • 要在活动类中执行此操作,可以通过
    super.setTheme(android.R.style.Theme.Holo.Light)
用于数字选择器
通过res/values/style.xml创建自定义样式

<?xml version.....>
<resources>
<style name="AndroDev" parent="@android:style/Theme.Holo.Light">
    <item name="android:background">#ffffff</item>
</style>
</resources>

#ffffff
然后在定义数字选择器视图的xml中使用此选项:

<NumberPickerView style:"@style/AndroDev" ....>


我举了全息光主题的例子。您可以随意更改。

您应该添加代码以帮助其他人帮助您。我认为在您的情况下,这些是xml文件。您应该添加代码以帮助其他人帮助您。我想在你的例子中,这些是xml文件。在清单中,我有android:theme=“@android:style/theme.NoTitleBar”我已经按照你建议的那样为numberpicker做了同样的事情,但没有帮助…请告诉我该怎么做。你是否在style.xml中创建了新样式并应用于你的数字选择器?是的,我已经按照你提到的制作了新样式并应用于numberpicker…我编辑了我的主题样式。就用这个吧。同时从xml中删除android:background属性。我也做了同样的操作,但是数字选择器仍然没有根据holo主题进行更改。自从我为该活动使用@android:style/theme.Black.NoTitleBar主题以来,我的清单文件中是否有问题。在清单中,我有android:theme=“@android:style/theme.NoTitleBar”我已经按照你建议的那样为numberpicker做了同样的事情,但没有帮助…请告诉我该怎么做。你是否在style.xml中创建了新样式并应用于你的数字选择器?是的,我已经按照你提到的制作了新样式并应用于numberpicker…我编辑了我的主题样式。就用这个吧。同时从xml中删除android:background属性。我也做了同样的操作,但是数字选择器仍然没有根据holo主题进行更改。由于我为该活动使用了@android:style/theme.Black.NoTitleBar主题,我的清单文件中是否存在问题。