Working in an android app,Here I have a TimePicker with spinner mode and my layout background color is black.So I want to change the color of the TimePicker's font to white [Hour,Minute,AM/PM].
I have referred and tried so many solutions for this from SO ,But nothing is solved my problem.
Finally I found a source Change the text color of NumberPicker
I have implemented as follows
import java.lang.reflect.Field;
public class CheckOut extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_alarm);
mTimePicker = (TimePicker) findViewById(R.id.mTimePicker);
int mycolor = getResources().getColor(R.color.tab_background);
setTimePickerColor(mTimePicker,mycolor);
}
public static boolean setTimePickerColor(TimePicker timePicker, int color)
{
final int count = timePicker.getChildCount();
for(int i = 0; i < count; i++){
View child = timePicker.getChildAt(i);
if(child instanceof EditText){
try{
Field selectorWheelPaintField = timePicker.getClass()
.getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
((Paint)selectorWheelPaintField.get(timePicker)).setColor(color);
((EditText)child).setTextColor(color);
timePicker.invalidate();
return true;
}
catch(NoSuchFieldException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalAccessException e){
Log.w("setNumberPickerTextColor", e);
}
catch(IllegalArgumentException e){
Log.w("setNumberPickerTextColor", e);
}
}
}
return false;
}
}
I don't know where I did the mistake ,Because it is not make any effect .
See Question&Answers more detail:os