Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

coding style - Android HoneyComb DatePicker Text Color

I'm searching for a possibilitie to adjust the text color of the datepicker widget in an android honeycomb app. I knew that the widget inherent the global text-color which is white in my case, but i need a black text-color for the datepicker as the background here is light grey.

Anyone know how to fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

DONE IT

Did it in a Theme in the application styles.xml (basically set a style on all EditText fields)

I have this in /values-v11/ so it only affects >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>

Then in my AndroidManifest, for the Activity that uses the DatePicker:

      <activity
            android:name=".ui.phone.SelectDateActivity"
            android:label="Date Selection"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.SelectDate" />

That's it!


My Working Out:

I came to this conclusion by checking the DatePicker source:

https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/date_picker.xml

That showed me the DatePicker used 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

The NumberPicker uses an EditText

You can therefore style an EditText

android : how to change the style of edit text?

And if you search in this file for "editText" you will see you can set a style on all edittext fields in one Activity!

https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml

You override this item:

 <item name="editTextStyle">@android:style/Widget.EditText</item>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...