EditText

1、默认文字

android:hint="为你的原创乐曲加一些描述吧,
能让更多人发现哦!
例如#古风#、#伤感#"

2、输入类型

android:inputType="textMultiLine" 输入为多行
android:inputType="numberPassword" 数字密码
android:inputType="text" 文字

...

3、光标位置


android:gravity="left|top"

 4、去除下划线

android:background="@null"

 5、设置行间距

android:lineSpacingMultiplier="1.2"
android:lineSpacingExtra="10dp"

 6、一开始不要显示光标(即成为焦点)

在父View加上


android:focusableInTouchMode="true"

 7、获取焦点并弹出键盘

et_user_phone.requestFocus();
et_user_phone.findFocus();
InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_user_phone, InputMethodManager.SHOW_FORCED);// 显示输入法

 8、点击回车键的监听

在EditText的属性上添加:

android:imeOptions="actionDone"

java中:

et_searchbox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // do something
                    myApp.MakeToast("搜索");
                }
                return true;
            }
        });

 9、失去焦点,并隐藏键盘

et_comment.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);

 10、修改回车键的显示文字(“完成”、搜索。。。)

android:imeOptions="actionSearch"
原文地址:https://www.cnblogs.com/zhaozilongcjiajia/p/10818502.html