Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the style of a DatePicker in android?

I want to change the default color of the date/time picker dialog in Android, so that it should match my app's theme. I searched for the solution on Google, but I couldn't find a solution.

What I was doing was creating a new style:

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

Don't know what are the attributes available for date picker dialogue. It would be great if anyone could post a link on that

and after adding the style I was calling it in my main style as

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

Unfortunately, this didn't work for me at all.

like image 912
silverFoxA Avatar asked May 14 '15 14:05

silverFoxA


People also ask

How can I change DatePicker size in android?

For example, android:layout_width="15dp" will set the width at a scalable value of 15. You can change 15 to whatever you want. If you want to set a specific pixel size, you can use, for example, 15px .


1 Answers

call like this

 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);       }      } 

follow this it will give you all type date picker style(copy from this)

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

enter image description here

enter image description here

enter image description here

like image 173
Avinash Ajay Pandey Avatar answered Oct 11 '22 11:10

Avinash Ajay Pandey