EditText不太常用又用得到的东西

本文详细介绍如何使用安卓EditText控件进行高级定制,包括站位文字、取消下划线、设置输入类型、键盘按钮样式、按钮点击事件、光标颜色、显示行数、左侧图标及行间距调整,同时涵盖监听输入的多种方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.站位文字

android:hint="请输入账号

2.取消下划线

android:background="@null

3.设置输入类型(密码,数字,电话号等)

android:inputType=“textPassword”

4.设置键盘return按钮显示类型(搜索,完成)

android:imeOptions=“actionSearch"

5.获取该按钮的点击事件

editText = findViewById(R.id.searchEditText);

editText.setOnEditorActionListener(this);

@Override

public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {

    if (keyEvent.getAction() == KeyEvent.ACTION_UP){//手指抬起时执行,不加条件会执行两次

        Log.e("胖虎",textView.getText().toString());

    }

    return true;

}

6.设置光标颜色

android:textCursorDrawable="@drawable/cursor"

cursor为声明的一个shape需要设置颜色和宽度

7.设置显示一行

android:maxLines=“1"

8.设置左侧图片

android:drawableLeft="@mipmap/sousuo

9.设置行间距

android:lineSpacingExtra=“3dp"

10.监听输入

editText.addTextChangedListener(this);

@Override//开始输入时执行

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

}

@Override//输入内容变化时执行

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

}

@Override//结束输入时执行

public void afterTextChanged(Editable editable) {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值