gpt4 book ai didi

android - 如何在 android 中更改 DatePicker 的样式?

转载 作者:IT老高 更新时间:2023-10-28 21:41:41 44 4
gpt4 key购买 nike

我想更改 Android 中日期/时间选择器对话框的默认颜色,使其与我的应用主题相匹配。我在 Google 上搜索了解决方案,但找不到解决方案。

我正在做的是创造一种新的风格:

  <style name="datepicker" parent="@android:style/Widget.DeviceDefault.DatePicker">
<!---TODO-->
<item name="android:focusedMonthDateColor">@android:color/holo_red_dark</item>
</style>

不知道日期选择器对话的可用属性是什么。如果有人可以在上面发布链接,那就太好了

添加样式后,我在我的主要样式中将其称为

 <item name="android:datePickerStyle">@style/datepicker</item>

不幸的是,这对我根本不起作用。

最佳答案

这样打电话

 button5.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

DialogFragment dialogfragment = new DatePickerDialogTheme();

dialogfragment.show(getFragmentManager(), "Theme");

}
});

public static class DatePickerDialogTheme extends DialogFragment implements DatePickerDialog.OnDateSetListener{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
final Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);

//for one

//for two

DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_DARK,this,year,month,day);

//for three
DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT,this,year,month,day);

// for four

DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_DARK,this,year,month,day);

//for five

DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_HOLO_LIGHT,this,year,month,day);

//for six

DatePickerDialog datepickerdialog = new DatePickerDialog(getActivity(),
AlertDialog.THEME_TRADITIONAL,this,year,month,day);


return datepickerdialog;
}

public void onDateSet(DatePicker view, int year, int month, int day){

TextView textview = (TextView)getActivity().findViewById(R.id.textView1);

textview.setText(day + ":" + (month+1) + ":" + year);

}
}

按照这个它会给你所有类型的日期选择器样式(从这里复制)

http://www.android-examples.com/change-datepickerdialog-theme-in-android-using-dialogfragment/

enter image description here

enter image description here

enter image description here

关于android - 如何在 android 中更改 DatePicker 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30239627/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com