I have a PreferenceFragment that loads preferences by calling addPreferencesFromResource(R.xml.preferences_main);
In side the preferences_main.xml file I have a custom preference called TimePreference which extends DialogPreference. TimePreference contains nothing but a TimePicker (have also tried DatePicker). When displayed the TimePicker is now a different format. Instead of being a spinner, it is the version with EditText views and up/down arrows. The real problem is those arrows are white and the text is white, all on a white background dialog.
If I put a TimePicker on an activity, it is the themed spinner style.
I cannot find out why this only happens on a DialogPreference and not on the activity. Its like it loses all styling.
My base theme is Theme.AppCompat.Light, I have tried a couple others with the same result.
Edit: My minSdkVersion is 11 and the target is 19
Anyone have any ideas?
public class TestPreference extends DialogPreference {
Button btn;
TimePicker tp;
public TestPreference(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected View onCreateDialogView() {
tp = new TimePicker(getContext().getApplicationContext());
return tp;
}
}
You are using Application context which does not hold any information about theme/style chose for your application.
Try changing the initialization of TimePicker
as below and see if it works:
tp = new TimePicker(getContext());
Moreover, when creating an instance of your TestPreference
, pass your activity's reference in its constructor, for example: YourActivity.this
.