'Material Date Picker title is out of place

I'm having this weird issue when using MaterialDatePicker. While it works, the title and current date are not displaying as they should.

Any ideas on what is happening?

I'm using Material Components library version 1.2.0

This is the result I'm getting:

enter image description here

I'm using the default style for the MaterialDatePicker and did not overload anything related to it, to the best of my knowledge.

This is the theme I'm using for this activity:

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@android:color/transparent</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Any hints or directions would be much appreciated!



Solution 1:[1]

try this code:-

  public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener{
        TextView textView;
        Button txt_open_date_picker;
        int yy,mm,dd;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            textView = findViewById(R.id.text);
            txt_open_date_picker = (Button) findViewById(R.id.txt_open_date_picker);
    
            txt_open_date_picker.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    DatePickerDialog datePickerDialog = new DatePickerDialog(
                            MainActivity.this,
                            MainActivity.this,
                            Calendar.getInstance().get(Calendar.YEAR),
                            Calendar.getInstance().get(Calendar.MONTH),
                            Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
    
                    datePickerDialog.show();
                }
            });
    
        }
    
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            String date = dayOfMonth + "/" + month + "/" + year;
            textView.setText(date);
        }
    }

Solution 2:[2]

My problem was using FragmentActivity. I switched to AppCompatActivity and it worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Android Developer
Solution 2 Nikita Makhno