3

我想在我的 inputText 键盘上应用发送操作,但是我仍然看到默认箭头,而不是发送按钮。我还尝试了几种不同版本的设备,但问题仍然存在。

XML:

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/layout"
        style="@style/AppEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/dimen_16"
        android:layout_marginEnd="@dimen/dimen_16"
        app:counterMaxLength="9"
        app:helperText="@string/idnow_landing_helper_text"
        app:helperTextEnabled="true"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="parent">

    <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
            android:imeOptions="actionSend"
            android:inputType="textCapCharacters"
            android:maxLength="9"
            android:textColor="@color/grayDark"/>
</com.google.android.material.textfield.TextInputLayout>

活动:

 override fun onCreate(savedInstanceState: Bundle?) {
     ...
      findViewById<EditText>(R.id.edit_text).setOnEditorActionListener { v, actionId, event ->
        return@setOnEditorActionListener when (actionId) {
            EditorInfo.IME_ACTION_SEND -> {
                //do things
                true
            }
            else -> false
        }
    }
 }
4

2 回答 2

4

解决方案是添加:

android:singleLine="true"

结果:

<com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:imeOptions="actionSend"
            android:inputType="textCapCharacters"
            android:singleLine="true"
            android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
            android:maxLength="9"
            android:textColor="@android:color/black"/>
于 2019-07-19T08:05:21.300 回答
1

用下面的替换 TextInputEditText

<com.google.android.material.textfield.TextInputEditText
                android:id="@+id/edit_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                android:imeOptions="actionSend"
                android:inputType="textCapCharacters"
                android:maxLength="9"
                android:textColor="@android:color/black"/>

您将在键盘上获得发送按钮,并且还将在活动中收到回调。

让我知道以获得更多帮助。

于 2019-07-18T17:24:23.603 回答