我正在寻找一种可能性来调整 Android 蜂窝应用程序中日期选择器小部件的文本颜色。我知道小部件固有的全局文本颜色在我的例子中是白色的,但我需要日期选择器的黑色文本颜色,因为这里的背景是浅灰色。
有人知道如何解决这个问题吗?
最佳答案
完成
是否在应用程序 styles.xml 的主题中(基本上在所有 EditText 字段上设置样式)
我在/values-v11/中有这个,所以它只影响 >HC
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.SelectDate" parent="@android:style/Theme.Holo.NoActionBar">
<item name="android:editTextStyle">@style/Widget.EditText.Black</item>
</style>
<style name="Widget.EditText.Black" parent="@android:style/Widget.EditText">
<item name="android:textColor">@color/black</item>
</style>
</resources>
然后在我的 AndroidManifest 中,对于使用 DatePicker 的 Activity:
<activity
android:name=".ui.phone.SelectDateActivity"
android:label="Date Selection"
android:screenOrientation="portrait"
android:theme="@style/Theme.SelectDate" />
就是这样!
我的锻炼:
我通过查看 DatePicker 源码得出这个结论:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/date_picker.xml
向我展示了 DatePicker 使用了 NumberPicker
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/number_picker.xml https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/number_picker_with_selector_wheel.xml
NumberPicker 使用 EditText
因此您可以设置 EditText 的样式
android : how to change the style of edit text?
如果您在此文件中搜索“editText”,您将看到您可以在一个 Activity 中的所有 edittext 字段上设置样式!
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml
你覆盖了这个项目:
<item name="editTextStyle">@android:style/Widget.EditText</item>
关于Android HoneyComb DatePicker 文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8837480/