如何更改DatePicker对话框的颜色
我喜欢更改DatePicker对话框的颜色。我加载对话框为如何更改DatePicker对话框的颜色
@SuppressLint("NewApi")
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@SuppressLint("NewApi")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}
@SuppressLint("NewApi")
public void showDatePickerDialog(View v) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");//show(getSupportFragmentManager(), "datePicker");
}
当它加载对话框时,它是白色背景。如何更改为显示第二张图片中显示的颜色? 谢谢
这是我会尝试。对于Android < = 2.3(API 10/v10),将主题从Android 3.0(API 11/v11)中的默认Android轻量级主题延伸出来,我将从holo light主题延伸。你可以看到如何在这里做到这一点: How to use Holo.Light theme, and fall back to 'Light' on pre-honeycomb devices?
我不是100%肯定这会改变你的警告对话框,因为我没有使用过光的主题广泛,所以你可能需要编辑的属性或两个从轻的主题到获得编辑文本的背景变得轻松。
根据您的查询,您必须创建自定义对话框主题并设置在custom_theme.xml
现在只需根据您的API
版本进行设置即可。
首先,在值增加的themes.xml这样的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Any customizations for your app running on pre-3.0 devices here -->
</style>
</resources>
然后,创建于res目录名称“值-V11”(Android 3.0以上版本)的目录,并把一个主题。这样
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
<!-- Any customizations for your app running on 3.0+ devices here -->
</style>
</resources>
最后的XML,创建一个目录,在res目录名称 “值-V14”(Android 4.0以上版本),并创建一个的themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<!-- Any customizations for your app running on 4.0+ devices here -->
</style>
</resources>
For More Details查看链接并关注它。
希望你对他们有一些想法并解决你的问题。
祝你好运。
感谢chintan khetiya你的链接帮了我很多.. – Venkat 2013-05-04 10:51:56
请接受:P – 2013-05-04 10:53:09
结帐这里的答案 - http://stackoverflow.com/questions/6729697/set-android-theme-light-for-alert-dialog – 2013-04-10 13:19:21
一个使用AlertDialog.Builder建设者=新AlertDialog.Builder( 新ContextThemeWrapper (context,R.style.popup_theme));并改变主题。但对我来说,我使用newFragment.show(getFragmentManager(),“datePicker”);我怎样才能改变主题? – Bryanyan 2013-04-10 13:27:42