ImeOptions не работает для CustomEditText

Мне нужно установить imeOptions на мой CustomEditText. Но imeOptions недоступен.

Мой CustomEditText:

public class CustomEditText extends AppCompatEditText {
    private Context context;

    public CustomEditText(Context context) {
        super(context);
        this.context = context;
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
    }
}

Поскольку AppCompatEditText имеет imeOptions, наследование от него должно работать. Как вы их пытаетесь установить?

Gabe Sechan 19.04.2018 15:03
0
1
49
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Ответ принят как подходящий

Ваш код CustomEditText работает нормально в моем устройстве

Вам нужно установить android:inputType = "text" с помощью android:imeOptions = "actionNext"

Вы можете установить inputType и imeOptions в соответствии с вашими требованиями

Проверьте этот пример ниже

<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:tools = "http://schemas.android.com/tools"
    android:id = "@+id/scrollView"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:orientation = "vertical">

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:imeOptions = "actionNext"
        android:inputType = "text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:imeOptions = "actionNext"
        android:inputType = "text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:imeOptions = "actionNext"
        android:inputType = "text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:imeOptions = "actionNext"
        android:inputType = "text" />

    <com.example.nilesh.testapp.CustomEditText
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:imeOptions = "actionNext"
        android:inputType = "text" />

</LinearLayout>

make, чтобы установить imeOption, как показано ниже:

public class CustomEditText extends AppCompatEditText {
    private Context context;

    public CustomEditText(Context context) {
        super(context);
        this.context = context;
        setImeOption();
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        setImeOption();
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        setImeOption();
    }

private void setImeOption() {
                this.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            }

    }

Другие вопросы по теме