【问题标题】:imeOptions="actionSend" not working in material designimeOptions="actionSend" 在材料设计中不起作用
【发布时间】:2019-11-27 15:59:39
【问题描述】:

我想在我的 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
        }
    }
 }

【问题讨论】:

    标签: android imeoptions


    【解决方案1】:

    解决办法是添加:

    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"/>
    

    【讨论】:

      【解决方案2】:

      将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"/>
      

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

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

      【讨论】:

      • 为什么要取出数字?我需要它来排除数字的输入
      • @rguerra:我的解决方案对你有用吗?数字除外。
      • 是的,但为什么我不能将数字与 imeOptions 结合起来? @Hardik Bmbhania
      猜你喜欢
      • 2012-07-30
      • 2020-02-09
      • 1970-01-01
      • 2023-03-07
      • 2015-10-10
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      相关资源
      最近更新 更多