【问题标题】:How to change application theme in Eclipse如何在 Eclipse 中更改应用程序主题
【发布时间】:2014-08-05 14:23:20
【问题描述】:

我想将日期选择器的背景从白色更改为黑色,我认为可以通过将我的应用主题更改为全息黑暗来完成。

目前是: 我想把它改成全息黑

所以,目前我在 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="Theme.AppCompat.Light">
    <!--
        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>

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="Theme.AppCompat.Light">
    <!-- API 11 theme customizations can go here. -->
</style>

</resources>

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="Theme.AppCompat.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>

</resources>

Mainifest.xml

<application
   .....
   android:theme="@style/AppTheme" >
   .......
</application>

我正在使用 appcompat_v7,那么我应该如何修改我的 styles.xml 使用 Holo Light and Dark Date Picker?

【问题讨论】:

  • 你在使用 HoloEverywhere 吗?如果您不使用它,请删除标签。
  • 这里可以找到解决问题的线索:stackoverflow.com/q/18839895
  • 一条线索总是令人沮丧和折磨,除非它解决了你的问题
  • 如何在可视化布局编辑器中更改该屏幕的样式?
  • @jesses.co.tt 如果我们使用自定义对话框,这是可能的,但是自定义日期选择器将是一个很大的麻烦!

标签: android xml eclipse android-theme android-appcompat


【解决方案1】:

在应用使用 appcompat_v7 时将 Theme.AppCompat 设置为主题的父级解决了这个问题!

Theme.AppCompat 在视觉上与 Theme.Holo(深色)相同。

有关更多信息,请参阅 Android 文档ActionBar 了解更多信息!

【讨论】:

    【解决方案2】:

    解决方案是:: android:Theme.Holo


    复制此代码并将其粘贴到 styles.xmlvalues 文件夹中

    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: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>
    

    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>
    

    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>
    

    Mainifest.xml

    <application
       .....
       android:theme="@style/AppTheme" >
       .......
    </application>
    

    - 看看 --- HOLO_EVERYWHERE - PROJECT - CLICK -HERE

    - 看看 --- DEVELOPER_SITE - CLICK - HERE

    【讨论】:

    • 谢谢,但应用程序因java.lang.RuntimeException: Unable to start activity ComponentInfo{com...}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.而崩溃
    • @VivekWarde .... 您必须检查其他包含样式文件的文件夹,这些文件夹可能会覆盖您的样式。 ...你这样做了吗?
    • 你指的其他文件夹是什么意思?顺便说一句,styles.xml 在我指定的文件夹中,我已经根据你指定的修改了所有代码!
    • 对不起,你的回答完全错了,看我的回答!
    • 我不知道你在使用appcompat_v7 ...。我的回答是支持v4 ...我忘了问...很高兴你能解决它!干杯!
    【解决方案3】:

    好的,所以所有个实例......

        "Theme.AppCompat.Light"
    

    ...需要改成...

        "Theme.AppCompat"
    

    "Theme.AppCompat"appcompat 版本的 "Theme.Holo" - 暗版

    您不能使用"Theme.Holo",因为您使用的是appcompat 库。它们不兼容。遵循这个,它会起作用的!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 2021-08-03
      • 2011-12-06
      • 1970-01-01
      • 2022-01-06
      • 2013-07-14
      • 1970-01-01
      相关资源
      最近更新 更多