3

enter image description here

As you can tell, I'm using date picker (different language.. On the top is written November 2015).

I'm using OnClickListener, when a1 EditText is clicked, DatePicker Dialog is poping up and you will be able to choose date and when you finish you receive the date in the EditText.

But I'm having trouble with conformation button of the dialog and the years choosing, they are invisible and I can only click them, though not seeing them.

How can I enable/visible the buttons of the conformation and years date picking?

Activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_first_entry"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.none.myapplication.firstEntry">
<EditText
        android:id="@+id/a1"
        android:layout_below="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

Activity.java

private EditText a1;
private DatePickerDialog fromDatePickerDialog;
private SimpleDateFormat dateFormatter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first_entry);


    dateFormatter = new SimpleDateFormat("dd-MM-yyyy");

    findViewsById();

    setDateTimeField();

}
private void findViewsById() {
    a1 = (EditText) findViewById(R.id.a1);
    a1.setInputType(InputType.TYPE_NULL);
    a1.requestFocus();
}

private void setDateTimeField() {
    a1.setOnClickListener(this);

    Calendar newCalendar = Calendar.getInstance();
    fromDatePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar newDate = Calendar.getInstance();
            newDate.set(year, monthOfYear, dayOfMonth);
            a1.setText(dateFormatter.format(newDate.getTime()));
        }

    },newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
}


@Override
public void onClick(View view) {
    if(view == a1) {
        fromDatePickerDialog.show();
    }
}
Yotam Dahan
  • 689
  • 1
  • 9
  • 33
  • Click `year` caption on top to change whole year, click another time and you can pick decade. It works on many datapicker that I used as app user so it should work also here. – miljon May 05 '17 at 09:52
  • @miljon You are right, I couldn't see that because that also invisible to me. – Yotam Dahan May 05 '17 at 09:55

3 Answers3

7
fromDatePickerDialog = new DatePickerDialog(this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
    //rest of the code
}

and in your styles.xml

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/blue_500</item>
</style>

original answer

Community
  • 1
  • 1
shinilms
  • 1,494
  • 3
  • 22
  • 35
0

Check this code snippet -

public void showDatePickerDialog(){

        DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), date, myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
        datePickerDialog.show();
       //clientDate.setText(""+myCalendar.get(Calendar.DAY_OF_MONTH)+"/"+(myCalendar.get(Calendar.MONTH)+1)+"/"+myCalendar.get(Calendar.YEAR));
    }


    DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

            myCalendar.set(Calendar.YEAR, year);
            myCalendar.set(Calendar.MONTH, monthOfYear);
            myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            //updateYourLabel(); // or whatever you want
            //Toast.makeText(context, ""+dayOfMonth+"/"+(monthOfYear+1)+"/"+year, Toast.LENGTH_SHORT).show();
            clientDate.setText(""+dayOfMonth+"/"+(monthOfYear+1)+"/"+year);
        }

    };
Vikas Sachdeva
  • 5,633
  • 2
  • 17
  • 26
0

For those who didn't get above solutions useful, try this solution-

styles.xml:

<!--  Date Picker Styles   -->
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">@color/titletext_blue</item>           <!-- Header Background -->
    <item name="android:colorAccent">@color/titletext_blue</item>
    <item name="android:textColor">@color/titletext_blue</item>
    <item name="android:buttonBarPositiveButtonStyle">@style/DialogButtonStyled</item>
    <item name="android:buttonBarNegativeButtonStyle">@style/DialogButtonStyled</item>
    <item name="android:buttonBarNeutralButtonStyle">@style/DialogButtonStyled</item>
    <item name="android:colorControlActivated">#4971AC</item>        <!--selected day-->
    <!--        <item name="android:textColorPrimary">#89B5F6</item> &lt;!&ndash;days of the month&ndash;&gt;-->
    <!--        <item name="android:textColorSecondary">#0E3E85</item>    &lt;!&ndash;days of the week&ndash;&gt;-->
</style>

<!-- Date picker ok/cancel button styles    -->
<style name="DialogButtonStyled" parent="Theme.MaterialComponents.Light">
    <item name="android:textColor">@color/titletext_blue</item>
    <item name="android:background">@color/transparent</item>
    <item name="android:textSize">15dp</item>
</style>

And call date picker as follows:

new DatePickerDialog(getActivity(), R.style.DialogTheme,(DatePickerDialog.OnDateSetListener) getActivity(), year, month, day);

This should help you :) Cheers!

Akshay Chavan
  • 185
  • 1
  • 6