Android - EditView属性

来源:互联网 发布:java list json 转换 编辑:程序博客网 时间:2024/05/16 15:22

1、获取焦点

三个方法必须同时设定

private EditText passwde = null;   passwde.setFocusable(true);   passwde.setFocusableInTouchMode(true);   passwde.requestFocus();  

2、数字

这条可以让输入法自动变为数字输入键盘,同时仅允许0-9的数字输入

android:inputType="number"

3、设置背景

etWorkName.setBackgroundResource(R.color.app_style_color);
4、设置提示文字

etWorkName.setHint("请输入作品姓名哦");

5、dialog中弹出输入法

(1) 在自定义的dialog中增加如下方法:

public void showKeyboard() {          if(editText!=null){              //设置可获得焦点              editText.setFocusable(true);              editText.setFocusableInTouchMode(true);              //请求获得焦点              editText.requestFocus();              //调用系统输入法              InputMethodManager inputManager = (InputMethodManager) editText                      .getContext().getSystemService(Context.INPUT_METHOD_SERVICE);              inputManager.showSoftInput(editText, 0);          }      } 
其中editText为自定义dialog中的输入框的view

(2) 在dialog.show()后,调用这个方法显示输入法,由于在调用时可能dialog界面还未加载完成,editText 可能还为空,所以需要加上一个延时任务,延迟显示:

dialog.show();  Timer timer = new Timer();  timer.schedule(new TimerTask() {        @Override      public void run() {          dialog.showKeyboard();      }  }, 200);



0 0
原创粉丝点击