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) {
}