I am new to android development and currently trying to integrate material design into my app.
I would like to evaluate a simple form, for this purpose I used the components com.google.android.material.textfield.TextInputLayout
and com.google.android.material.textfield.TextInputEditText
for user input. Besides the text input, I need a date, which I want to read with a MaterialDatePicker
.
I tried to display the MaterialDatePicker
with OnFocusChangeListener
, this works too, but I have two problems.
- the display is a little bit delayed because first a keyboard is opened which is closed immediately after calling the
MaterialDatePicker
. - when the display is closed with the Back button, the focus is still on TextInputLayout. So I would have to change the focus first to open a
MaterialDatePicker
again.
This is how I implemented the OnFocusChangeListener
@Override
public void onFocusChange(View view, boolean selected) {
if( view.getId() == R.id.myId&& selected ){
MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.datePicker();
MaterialDatePicker picker = builder.build();
picker.show( this.getParentFragmentManager(), "DATE_PICKER" );
}
}
Are there alternative components of Material Design that are better suited for the presentation? I would like to keep the behavior within the form, so as soon as the date is entered by the user, a small label should be displayed above, like this:
Thank you for your help.