简体   繁体   English

如何强制用户仅在edittext中输入表情符号

[英]How can I force user to enter emoji only in edittext

I'm using androidx.emoji.widget.EmojiEditText. 我正在使用androidx.emoji.widget.EmojiEditText。 I want to force user to enter only emojis here. 我想强制用户仅在此处输入表情符号。 And limit him to max 3 emojis. 并限制他最多3个表情符号。 How can I do something like this? 我该怎么做? I tried to use external emoji keyboard that cancels the soft keyboard and shows up but didn't work properly. 我尝试使用外部表情符号键盘,该键盘取消了软键盘并显示但无法正常工作。

<androidx.emoji.widget.EmojiEditText
                            android:id="@+id/etEmoji"
                            android:layout_width="match_parent"
                            android:layout_height="30dp"
                            android:layout_margin="10dp"
                            android:hint="Enter Emoji"
                            android:inputType="textShortMessage"
                            android:background="@android:color/transparent"/>

Below class will only allow Emojis and symbols. 下面的课程仅允许使用表情符号和符号。

public class CustomEditText extends EditText {
        public CustomEditText(Context context) {
            super(context);
            init();
        }

        public CustomEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }

        public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            init();
        }

        private void init() {
            setFilters(new InputFilter[]{new EmojiIncludeFilter()});
        }

        private class EmojiIncludeFilter implements InputFilter {

            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                for (int i = start; i < end; i++) {
                    int type = Character.getType(source.charAt(i));
                    if (type != Character.SURROGATE && type != Character.OTHER_SYMBOL) {
                        // Other then emoji value will be blank
                        return "";
                    }
                }
                return null;
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制用户输入带有符号的密码? - How can I force user to enter password with symbol(s) inside? 如果用户输入某个关键字并显示它,我如何让editText获取stringarray的值? - How can i make the editText get the value of stringarray if the user enter certain keyword and display it? 我如何强迫用户单击通知 - How can i force the user to click the notification 我怎么知道,有多少个EditText用户添加? - How can I know, how many EditText user add? 我还如何使enter将edittext中的输入文本添加到列表视图? 在创建的添加按钮之上 - How can I also make enter add input text in edittext to my listview? On top of the created add button 当用户在editText中输入任何金额时如何附加$? - How to append $ when user enter any amount into the editText? 如何允许在编辑文本中使用特定字符串并将这些字符串显示给用户? - How can I allow specific strings in an edittext and show these string to the user? 如何让用户“输入”答案并使editText消失? [ANDROID STUDIO] - How to let user 'Enter' an answer and make editText disappear? [ANDROID STUDIO] JavaFX:如何显示表情符号? - JavaFX: How can I display Emoji? 我如何要求用户重新输入他们的选择? - How can I ask the user to re-enter their choice?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM