How to add `Done` and `Cancel` imei option on android keyboard for edit text

Viewed 98

not sure if this is possible,

I have an edit text and when it is clicked a number keypad opens and I want to add actionSend which will make an api call to send the value in the edit text.

If the user has edited the value in edit text and now wants to get back to previous value. is it possible to have another imeiOption on keyboard like a cancel with X which will get the previous value back(I will write the logic in the setOnEditorActionListener).

Is it possible to have two imeiOptions on key board at the same time Send and Cancel at the same time so that user can revert the changes.

if there is any other way to achieve this please do suggest (I can have two buttons on top of keyboard but want to check what I can do with IMEI options)

Thanks in advance R

            <EditText
                android:id="@+id/etCostLimit"
                style="@style/EditText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:gravity="center_horizontal"
                android:inputType="numberSigned|numberDecimal"
                android:digits="0123456789.,-"
                android:hint="@string/charge_restrictions_cost_placeholder"
                android:imeOptions="actionSend"
                app:layout_constraintWidth_percent="0.30"
                app:layout_constraintStart_toEndOf="@+id/tvNeverChangeOver"
                app:layout_constraintTop_toBottomOf="@+id/dividerLineHorizontal" />

 etCostLimit.setOnEditorActionListener { v, actionId, event ->
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            // Your action on done
                Toast.makeText(context, "done clicked", Toast.LENGTH_LONG).show()
            // api call closed the closed the keyboard
            false 
        } else false
    }
1 Answers

is it possible to have another imeiOption on keyboard like a cancel with X which will get the previous value back

No. Bear in mind that keyboard options are hints, not demands. There are hundreds of soft keyboard (IME) implementations, and none have to honor your hints. So, you will either have zero or one action button (not two), and your app needs to work in either case. Never assume that the soft keyboard will show an action button.

Is it possible to have two imeiOptions on key board at the same time Send and Cancel at the same time so that user can revert the changes.

No.

Related