首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >imeOptions不为CustomEditText工作

imeOptions不为CustomEditText工作
EN

Stack Overflow用户
提问于 2018-04-19 12:23:04
回答 2查看 53关注 0票数 0

我需要在我的imeOptions上设置CustomEditText。但是imeOptions是不可用的。

我的CustomEditText:

代码语言:javascript
复制
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;
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-19 12:35:58

你的CustomEditText代码在我的分支中运行得很好

您需要使用android:inputType="text"设置android:imeOptions="actionNext"

您可以根据需要设置inputTypeimeOptions

请检查下面的示例

代码语言:javascript
复制
<?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>
票数 1
EN

Stack Overflow用户

发布于 2018-04-19 12:36:23

创建设置imeOption的方法,如下所示:

代码语言:javascript
复制
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);
            }

    }
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49921045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档