简体   繁体   English

EditText TimePicker 显示键盘

[英]EditText TimePicker shows KeyBoard

I have an EditText, which should open a TimePicker, but instead of it it opens the keyboard and once I remove the keyboard with the arrow, go back, and the next press shows the TimePicker.我有一个 EditText,它应该打开一个 TimePicker,但它不是打开键盘,一旦我用箭头移除键盘,就返回,下一次按下会显示 TimePicker。

How do I get the TimePicker to display directly without the keyboard?如何让 TimePicker 在没有键盘的情况下直接显示?

I leave the xml here:我把xml留在这里:

<com.google.android.material.textfield.TextInputLayout
            style="@style/TextInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/fInicio">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/fIni"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLines="1"
                android:textColor="@color/colorAccent" />
        </com.google.android.material.textfield.TextInputLayout>

and the Java Code:和Java代码:

 fIni.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int anno = calendario.get(Calendar.YEAR);
                int mes = calendario.get(Calendar.MONTH);
                int dia = calendario.get(Calendar.DAY_OF_MONTH);

                final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                        calendario.set(Calendar.YEAR, year);
                        calendario.set(Calendar.MONTH, monthOfYear);
                        calendario.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                        fechaInicio = String.format("%02d/%02d/%04d", dayOfMonth,monthOfYear,year);
                        fIni.setText(fechaInicio);

                        if (!fechaFin.equals(""))
                        {
                            if (testChar(fFin.toString()))
                            {
                                Date fI = ParseFecha(fechaInicio);
                                Date fF = ParseFecha(fechaFin);

                                d=restarFechas(fI,fF);

                                dias.setText(String.valueOf(d));
                            }
                        }


                    }
                };
                new DatePickerDialog(NueAvaCuando.this, date, anno,mes,dia).show();
            }
        });

Add this into EditText将此添加到EditText

android:cursorVisible="false"
android:focusable="false"
android:inputType="none"

Like that:像那样:


            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/fIni"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:cursorVisible="false"
                android:focusable="false"
                android:inputType="none"
                android:maxLines="1"
                android:textColor="@color/colorAccent" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM