sil*_*oxA 39 android android-datepicker android-timepicker android-styles
我想更改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>
不幸的是,这对我来说根本不起作用.
Avi*_*dey 68
像这样打电话
 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/
sil*_*oxA 55
试试这个.这是最简单,最有效的方式
<style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/primary</item>
</style>
Arn*_*Rao 26
要DatePicker在应用程序级别更改颜色(日历模式),请定义以下属性.
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
    <item name="colorAccent">#ff6d00</item>
    <item name="colorControlActivated">#33691e</item>
    <item name="android:selectableItemBackgroundBorderless">@color/colorPrimaryDark</item>
    <item name="colorControlHighlight">#d50000</item>
</style>
有关其他自定义样式,请参见http://www.zoftino.com/android-datepicker-exampleDatePicker
Vin*_*dav 15
Calendar calendar = Calendar.getInstance();
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.DatePickerDialogTheme, new DatePickerDialog.OnDateSetListener() {
  public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    Calendar newDate = Calendar.getInstance();
    newDate.set(year, monthOfYear, dayOfMonth);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
    String date = simpleDateFormat.format(newDate.getTime());
  }
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show();
并使用这种风格
<style name="DatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
  <item name="colorAccent">@color/colorPrimary</item>
</style>
Roh*_*har 11
创建自定义DatePickerDialog样式:
<style name="AppTheme.DatePickerDialog" parent="Theme.MaterialComponents.Light.Dialog">
    <item name="android:colorAccent">@color/colorPrimary</item>
    <item name="android:colorControlActivated">@color/colorPrimaryDark</item>
    <item name="android:buttonBarPositiveButtonStyle">@style/AppTheme.Alert.Button.Positive</item>
    <item name="android:buttonBarNegativeButtonStyle">@style/AppTheme.Alert.Button.Negative</item>
    <item name="android:buttonBarNeutralButtonStyle">@style/AppTheme.Alert.Button.Neutral</item>
</style>
<style name="AppTheme.Alert.Button.Positive" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="android:textColor">@color/buttonPositive</item>
</style>
<style name="AppTheme.Alert.Button.Negative" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="android:textColor">@color/buttonNegative</item>
</style>
<style name="AppTheme.Alert.Button.Neutral" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="android:textColor">@color/buttonNeutral</item>
</style>
datePickerDialogTheme在应用程序主题中设置自定义样式:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="android:datePickerDialogTheme">@style/AppTheme.DatePickerDialog</item>
</style>
在初始化时以编程方式设置主题,如下所示:
val datetime = DatePickerDialog(this, R.style.AppTheme_DatePickerDialog)
(我使用的是 React Native;targetSdkVersion 22)。我正在尝试更改日历日期选择器对话框的外观。接受的答案对我不起作用,但确实如此。希望这个片段可以帮助你们中的一些人。
<style name="CalendarDatePickerDialog"  parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#6bf442</item>
    <item name="android:textColorPrimary">#6bf442</item>
</style>
由于AlertDialog.THEME不推荐使用属性,因此在创建时DatePickerDialog您应该将这些参数之一传递给int themeResId
小智 6
创造新风格
<style name="my_dialog_theme" parent="ThemeOverlay.AppCompat.Dialog">
    <item name="colorAccent">@color/colorAccent</item>                   <!--header background-->
    <item name="android:windowBackground">@color/colorPrimary</item>     <!--calendar background-->
    <item name="android:colorControlActivated">@color/colorAccent</item> <!--selected day-->
    <item name="android:textColorPrimary">@color/colorPrimaryText</item> <!--days of the month-->
    <item name="android:textColorSecondary">@color/colorAccent</item>    <!--days of the week-->
</style>
然后初始化对话框
Calendar mCalendar = new GregorianCalendar();
mCalendar.setTime(new Date());
new DatePickerDialog(mContext, R.style.my_dialog_theme, new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        //do something with the date
    }
}, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)).show();
结果:https : //i.stack.imgur.com/zlMpg.png
| 归档时间: | 
 | 
| 查看次数: | 82963 次 | 
| 最近记录: |