在TextInputEditText android上未触发onClick事件

时间:2019-01-22 13:52:23

标签: android onclick onclicklistener android-textinputedittext

我有以下TextInputEditText

<com.google.android.material.textfield.TextInputLayout
            android:focusableInTouchMode="true"
            android:id="@+id/from_textinput"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            android:fontFamily="sans-serif"
            android:hint="@string/from"
            android:textColor="@color/colorDarkGrey"
            android:textColorHint="@color/colorDarkGrey"
            android:textSize="12sp"
            android:textStyle="normal"
            android:visibility="gone"
            app:boxCornerRadiusBottomEnd="5dp"
            app:boxCornerRadiusBottomStart="5dp"
            app:boxCornerRadiusTopEnd="5dp"
            app:boxCornerRadiusTopStart="5dp"
            app:boxStrokeColor="@color/colorPrimary"
            app:boxStrokeWidth="3dp"
            app:layout_constraintEnd_toStartOf="@+id/to_textinput"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/doNotDisturbCheckBox">

            <com.google.android.material.textfield.TextInputEditText
                android:onClick="@{() -> viewModel.openFromTimePickerClicked()}"
                android:focusableInTouchMode="true"
                android:id="@+id/from_textedit"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:editable="false"
                android:text="@{viewModel.doNotDisturbFrom}"
                android:textSize="16sp" />

        </com.google.android.material.textfield.TextInputLayout>

onClick不会在第一次触摸时触发的问题,只有在我第二次按下时才会调用

使其成为重点 第一次点击触发onClick

有人可以告诉我如何从第一时间触发点击

1 个答案:

答案 0 :(得分:1)

from_textedit.setEnabled(true);
from_textedit.setTextIsSelectable(true);
from_textedit.setFocusable(false);
from_textedit.setFocusableInTouchMode(false);
from_textedit.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Log.d(TAG, "Edit Text is clicked");
    }
});