Smi*_*lie 14 android coding-style datepicker textcolor
我正在寻找一种可能性来调整android蜂窝应用中的datepicker小部件的文本颜色.我知道这个小部件固有全局文本颜色,在我的情况下是白色的,但是我需要一个黑色文本颜色作为日期选择器,因为这里的背景是浅灰色.
有人知道怎么修这个东西吗?
Blu*_*ell 27
完成了
是否在应用程序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>
Run Code Online (Sandbox Code Playgroud)
然后在我的AndroidManifest中,对于使用DatePicker的Activity:
<activity
android:name=".ui.phone.SelectDateActivity"
android:label="Date Selection"
android:screenOrientation="portrait"
android:theme="@style/Theme.SelectDate" />
Run Code Online (Sandbox Code Playgroud)
而已!
我的锻炼:
我通过检查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的样式
如果您在此文件中搜索"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>
Run Code Online (Sandbox Code Playgroud)
小智 6
我找到了这个解决方案:调试DatePicker对象,我得到了jerarqy对象.也许这不是一个优雅的解决方案,但它的工作原理:
private void setNumberPickerProperties(DatePicker dp)
{
LinearLayout l = (LinearLayout)dp.getChildAt(0);
if(l!=null)
{
l = (LinearLayout)l.getChildAt(0);
if(l!=null)
{
for(int i=0;i<3;i++)
{
NumberPicker np = (NumberPicker)l.getChildAt(i);
if(np!=null)
{
EditText et = (EditText)np.getChildAt(1);
et.setTextColor(Color.BLACK);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 2
您好 :) 在日期选择器小部件中的某个位置有一个 EditText 小部件。你只需要找到它。您可以通过使用一些创造性的编码来完成此操作,并使用 getChildAt(index) 和 getChildCount() 等方法开始搜索 datepicker 小部件的子项,然后循环遍历它。
您也可以执行类似的操作,但我不确定它是否适用于所有设备,最好循环遍历 datepickers 子项:
DatePicker picker;
ViewGroup childpicker;
childpicker = (ViewGroup) findViewById(Resources.getSystem().getIdentifier("month" /*rest is: day, year*/, "id", "android"));
EditText textview = (EditText) picker.findViewById(Resources.getSystem().getIdentifier("timepicker_input", "id", "android"));
textview.setTextColor(Color.GREEN);
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助 :)
| 归档时间: |
|
| 查看次数: |
14231 次 |
| 最近记录: |