android EditText光标位置,光标样式,EditText限制输入内容,软键盘遮挡的EditText,搜索框,限制输入表情

2、指定输入内容


复制代码
android:digits="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"


mmet.addTextChangedListener(new TextWatcher() {

    @Override

    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {



    }



    @Override

    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        String editable = mmet.getText().toString();

        String regEx = "\[^a-zA-Z0-9\]";  //只能输入字母或数字

        Pattern p = Pattern.compile(regEx);

        Matcher m = p.matcher(editable);

        String str = m.replaceAll("").trim();    //删掉不是字母或数字的字符

        if (!editable.equals(str)) {

            mmet.setText(str);  //设置EditText的字符

            mmet.setSelection(str.length()); //因为删除了字符,要重写设置新的光标所在位置

        }

    }



    @Override

    public void afterTextChanged(Editable s) {



    }

});

3、光标样式


在drawable下创建editcolor
<?xml version="1.0" encoding="utf-8"?>

引用即可

<EditText

android:id="@+id/homesosoedit"

android:layout_width="180dp"

android:layout_height="25dp"

android:layout_marginLeft="5dp"

android:background="@null"

android:hint="请输入你要找的内容"

android:textColor="@color/login_black"

android:textColorHint="@color/bababa"

android:textCursorDrawable="@drawable/editcolor"

android:lineSpacingExtra="5dp"//行距

软键盘遮挡的EditText

==============

复制代码
@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);//键盘遮挡输入框


<android.support.v7.widget.SearchView

    android:id="@+id/keyWord"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:layout_gravity="center_vertical"

    android:imeOptions="actionSearch"

    android:inputType="textCapWords"

    android:singleLine="true"

    android:textColor="@android:color/white"

    android:textColorHint="@android:color/white"

    app:queryHint="请输入上车地点"

    app:searchIcon="@null" />

限制输入表情


使用方式

build :

compile 'com.xw.repo:xedittext:1.0.6@aar'

Layout (父布局加入命名空间):

xmlns:app="http://schemas.android.com/apk/res-auto"

EditText(所用代码):

<com.xw.repo.xedittext.XEditText

android:layout_width="match_parent"

android:layout_height="161dp"

android:background="@null"

android:gravity="top"

android:hint="请分享相关问题"

android:paddingLeft="17dp"

android:textColor="#999999"

android:textSize="13sp"

app:x_disableEmoji="true" />

禁止表情:

相关推荐
00后程序员张10 小时前
对比 Ipa Guard 与 Swift Shield 在 iOS 应用安全处理中的使用差异
android·开发语言·ios·小程序·uni-app·iphone·swift
悠哉清闲12 小时前
不同车型drawable不同
android·开发语言
00后程序员张14 小时前
在 iOS 设备上同时监控 CPU、GPU 与内存的方法
android·ios·小程序·https·uni-app·iphone·webview
测试_AI_一辰14 小时前
项目实践笔记 9:打卡/日报Agent项目Bug 修改与稳定性收口(v1.0)
android·开发语言·人工智能·功能测试·ai编程·ab测试
马 孔 多 在下雨14 小时前
Kotlin协程进阶王炸之作-Kotlin的协程到底是什么
android·开发语言·kotlin
冬奇Lab14 小时前
【Kotlin系列15】多平台开发实战:一次编写,多端运行
android·开发语言·kotlin
Dxy123931021615 小时前
告别默认排序:MySQL自定义排序的“炼金术”
android·数据库·mysql
请叫我大虾15 小时前
发现一个jdk中ArrayList的小BUG
android·java·bug
一起养小猫15 小时前
Flutter for OpenHarmony 实战:双控制系统实现(按钮+键盘)
android·flutter·计算机外设·harmonyos
_李小白16 小时前
【Android 美颜相机】第十八天:GPUImageChromaKeyBlendFilter 解析
android·数码相机