我一直试图改变我的timepicker的textcolor.但我无法找到父样式所在的位置.我试过了两个
<style name="MyTimePicker" parent="@android:style/Widget.Holo.TimePicker">
<item name="android:textColor">@color/text</item>
</style>
Run Code Online (Sandbox Code Playgroud)
和
<style name="MyTimePicker" parent="@android:style/Widget.TimePicker">
<item name="android:textColor">@color/text</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我minSdkVersion
是15.我targetSdkVersion
20岁.我已经重建并清理了我的项目.
我想我已经完成了所有关于SO的类似问题,但他们都没有真正为我提供解决方案.唯一可行的答案是使用某种类型的库,但我不是那个解决方案的忠实粉丝.父母的路径是否与我正在使用的不同,因为我很确定我应该能够以某种方式访问它?
编辑
这是主题的应用方式;
<TimePicker
style="@style/MyTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timePicker"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
Run Code Online (Sandbox Code Playgroud)
注意这是我收到的错误(忘记放置它):
错误:检索项目的父项时出错:找不到与给定名称"@android:style/Widget.Holo.TimePicker"匹配的资源.
编辑2 我看过的几个问题试图解决这个问题:
这些可能是我的问题的最佳问题/答案,但它们都没有帮助我.能够得到明确的答案真是太好了.
Bon*_*ono 23
我结合了Paul Burke的答案和Simon的答案,成功地编辑了文本的颜色TimePicker
.
以下是它的完成方式:
TimePicker time_picker; //Instantiated in onCreate()
Resources system;
private void set_timepicker_text_colour(){
system = Resources.getSystem();
int hour_numberpicker_id = system.getIdentifier("hour", "id", "android");
int minute_numberpicker_id = system.getIdentifier("minute", "id", "android");
int ampm_numberpicker_id = system.getIdentifier("amPm", "id", "android");
NumberPicker hour_numberpicker = (NumberPicker) time_picker.findViewById(hour_numberpicker_id);
NumberPicker minute_numberpicker = (NumberPicker) time_picker.findViewById(minute_numberpicker_id);
NumberPicker ampm_numberpicker = (NumberPicker) time_picker.findViewById(ampm_numberpicker_id);
set_numberpicker_text_colour(hour_numberpicker);
set_numberpicker_text_colour(minute_numberpicker);
set_numberpicker_text_colour(ampm_numberpicker);
}
private void set_numberpicker_text_colour(NumberPicker number_picker){
final int count = number_picker.getChildCount();
final int color = getResources().getColor(R.color.text);
for(int i = 0; i < count; i++){
View child = number_picker.getChildAt(i);
try{
Field wheelpaint_field = number_picker.getClass().getDeclaredField("mSelectorWheelPaint");
wheelpaint_field.setAccessible(true);
((Paint)wheelpaint_field.get(number_picker)).setColor(color);
((EditText)child).setTextColor(color);
number_picker.invalidate();
}
catch(NoSuchFieldException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalAccessException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalArgumentException e){
Log.w("setNumberPickerTextColor", e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,这个答案现在可能已经过时了.我不久前遇到了一些可能有问题的东西(详情请参阅我的问题).否则你应该按照Vikram的回答.
不知道为什么您需要为此深入研究 Java 反射 API。这是一个简单的造型问题。您需要覆盖的属性是:textColorPrimary
。
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
....
<item name="android:textColorPrimary">#ff0000</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如果您使用TimePicker
内部 a Dialog
,则覆盖android:textColorPrimary
对话框的主题。
就是这样。
添加到Vikram答案,将主题设置为 timePicker 不要将其设置为样式
在styles.xml
<style name="timePickerOrange">
<item name="android:textColorPrimary">@color/orange</item> <!-- color for digits -->
<item name="android:textColor">@color/orange</item> <!-- color for colon -->
<item name="android:colorControlNormal">@color/orange</item> <!-- color for (horizontal) delimeters -->
</style>
Run Code Online (Sandbox Code Playgroud)
对于 timePicker
<TimePicker
android:theme="@style/timePickerOrange"
android:id="@+id/timePicker_defaultTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/hero_regular"
android:timePickerMode="spinner"
app:fontFamily="@font/hero_regular" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19974 次 |
最近记录: |