您的位置:首页 > 移动开发 > Android开发

Android EditView

2015-11-25 10:16 357 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: