Android - 覆盖 theme.xml 样式

标签 android

我在 theme.xml 文件中定义了全局样式。这包括项目 <item name="colorControlActivated">@color/white</item> .

我有一个 DatePicker,它的选定日期背景使用此样式项,因此在白色背景上是白色的。因此,所选日期是不可见的。

这是日期选择器:

<DatePicker
    android:id="@+id/DatePicker"
    style="@style/date_picker_theme"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:calendarViewShown="false"
    android:descendantFocusability="blocksDescendants"
    android:endYear="2100"
    android:startYear="1900" />

我试图覆盖 colorControlActivated像这样的样式(在 styles.xml 中):

<style name="date_picker_theme">
    <item name="colorControlActivated">@color/green</item>
</style>

但这根本没有反射(reflect)出来。

如果我将 theme.xml 样式项更改为 <item name="colorControlActivated">@color/green</item>那么它反射(reflect)良好,但可能会改变整个应用程序的一些其他样式。

问题:如何只为我的 DatePicker 覆盖它?

现在的样子:

enter image description here

它应该是什么样子:

enter image description here

最佳答案

而不是将其设置为

style="@style/date_picker_theme"

设置为

android:theme="@style/date_picker_theme"

下面是完整的日期选择器 View

<DatePicker
  android:id="@+id/DatePicker"
  android:theme="@style/date_picker_theme"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:calendarViewShown="false"
  android:descendantFocusability="blocksDescendants"
  android:endYear="2100"
  android:startYear="1900" />

关于Android - 覆盖 theme.xml 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41486105/

相关文章:

android - 使用耗时类型设置警报会在内核中打印来自 dmesg 的不准确延迟

Android 5.0+ AudioManager setMode 不工作

android - 在没有错误日志的情况下 react native 应用程序崩溃,如何检测错误?

android - 在 Mac OS 上使用 gradle 从 SVG for Android 生成可绘制对象

android - 将 PreferenceScreen 类型设置为 "Select Contact"

android - 如何启动 Genius Scan 意向

android - 如何从Android上的地址获取经纬度?

java - Android 上的绑定(bind)服务与启动服务以及如何同时进行

java - Android - 将位图分配给 ImageView 会更改大小

android - 以编程方式列出所有默认应用程序