android中EditText的使用
2019-03-06 本文已影响0人
CarlosLynn
EditText设置输入类型为数字
xml
android:inputType="number"
代码
tvNum.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
EditText设置不可编辑
xml
android:inputType="none"
代码
tvNum.setInputType(EditorInfo.TYPE_NULL);
EditText设置可自动换行
android:inputType="textMultiLine"
<EditText
android:singleLine="false"
android:padding="@dimen/dp_10"
android:id="@+id/et_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_desc"
android:layout_alignLeft="@id/tv_desc"
android:layout_marginTop="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15"
android:background="@drawable/shape_et_bg"
android:gravity="left|top"
android:hint="请输入备注内容(可不填)"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:maxLength="99"
android:minHeight="@dimen/dp_100"
android:textColor="@color/c_101010"
android:textColorHint="@color/c_aaa4a4"
android:textCursorDrawable="@drawable/color_cursor"
android:textSize="@dimen/sp_12" />
EditText修改光标的颜色
定义光标背景图text_cursor_d_sp_opus_search
修改光标的颜色属性
android:textCursorDrawable="@drawable/text_cursor_d_sp_opus_search"
EditText设置未进行输入时候光标不闪烁
EditText设置光标不闪烁
android:cursorVisible="false"
EditText设置未进行输入时候光标不闪烁,
在EditText存在的xml布局中,找一个布局控件,加上
android:focusable="true"
android:focusableInTouchMode="true"
例如下面布局设置
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/c_ffffff"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingLeft="@dimen/dp_15"
android:paddingRight="@dimen/dp_15"
tools:context=".home.aviation.photo.frag.PlayInfoFrag">
<EditText
android:id="@+id/et_opus_no"
android:layout_width="@dimen/dp_240"
android:layout_height="@dimen/dp_40"
android:layout_below="@id/tv_opus_tag"
android:background="@drawable/bg_d_sp_opus_no"
android:inputType="number"
android:paddingLeft="@dimen/dp_10"
android:paddingRight="@dimen/dp_10"
android:textCursorDrawable="@drawable/text_cursor_d_sp_opus_search" />
<ImageView
android:id="@+id/tv_clear"
android:layout_width="@dimen/dp_40"
android:layout_height="wrap_content"
android:layout_alignTop="@id/et_opus_no"
android:layout_alignRight="@id/et_opus_no"
android:layout_alignBottom="@id/et_opus_no"
android:scaleType="center"
android:src="@drawable/icon_delete_vote" />
<TextView
android:id="@+id/tv_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/et_opus_no"
android:layout_alignBottom="@id/et_opus_no"
android:layout_marginLeft="@dimen/dp_10"
android:layout_toRightOf="@id/et_opus_no"
android:background="@drawable/bg_d_sp_search_opus_no"
android:gravity="center"
android:text="搜索"
android:textColor="@color/c_ffffff" />
</RelativeLayout>