开发过程中,EditText的一些常见问题
2017-02-17 14:15
330 查看
1、默认时不弹出软键盘(网上有好几种方法,但是我的代码中只有这个才有效,如果我的这个对你们无效,大家可以参考一下这个作者的:http://blog.csdn.net/sunny2come/article/details/12061027 )
解决办法:
在onCreate() 中加上getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);//默认时不弹出软键盘
2、EditText et_day填写四位后自动跳转到EditText et_hour;
解决办法:
3、EditText光标放在EditText中文本的末尾处:
解决办法:
EditText etext = mSubjectTextEditor.getText();
Selection.setSelection(etext, etext.length());
4、EditText光标看不见或者修改EditText光标的颜色:
解决办法:
EditText光标看不见可能的原因是光标颜色为白色;
设置EditText的 android:textCursorDrawable="@drawable/edit_cursor_color"
5、点击EditText要输入时,防止布局被顶上去:
解决办法:
在mainfest.xml中,对那个Activity加:
<activity android:name=".activity.HomeActivity"Android
4000
:windowSoftInputMode="adjustPan|stateHidden"></activity>
6、PopupWindowpop_reply中有EditText et_reply,防止EditText被输入法盖住:
(1)pop_reply.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
(2)、//获取焦点
7、//搜索页面中键盘搜索键的监听
解决办法:
private void initEditTextSearch(){
et_search.setOnEditorActionListener(newTextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextViewtextView, int actionId, KeyEvent keyEvent) {
if (actionId ==EditorInfo.IME_ACTION_SEARCH){
Log.e("ssss", "搜索");
//调用搜索的方法
return true;
}
return false;
}
});
}
8、android如何让输入框不能输入0:
解决办法:
EditTextView里有个属性,可以指定输入的值
android:digits="123456789" 表示可允许输入123456789
以上是我在开发时候遇到的问题,有问题欢迎指出,谢谢
解决办法:
在onCreate() 中加上getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);//默认时不弹出软键盘
2、EditText et_day填写四位后自动跳转到EditText et_hour;
解决办法:
et_day.addTextChangedListener(newTextWatcher() { @Override publicvoid beforeTextChanged (CharSequence s,int start, int count, int after) { } @Override public void onTextChanged (CharSequence s, intstart,int before, int count){ if (s.length() == 2) { //限定2个字符 et_hour.requestFocus(); } } @Override public void afterTextChanged (Editable s){ } });<?xml version="1.0"encoding="utf-8"?> onFocusChange(et_reply_content.isFocused()); privatevoid onFocusChange(boolean hasFocus) { final boolean isFocus = hasFocus; new Handler().postDelayed(new Runnable() { public void run() { InputMethodManager imm =(InputMethodManager) et_reply_content.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (isFocus) { imm.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS); } else { imm.hideSoftInputFromWindow(et_reply_content.getWindowToken(), 0); } } }, 100); }
3、EditText光标放在EditText中文本的末尾处:
解决办法:
EditText etext = mSubjectTextEditor.getText();
Selection.setSelection(etext, etext.length());
4、EditText光标看不见或者修改EditText光标的颜色:
解决办法:
EditText光标看不见可能的原因是光标颜色为白色;
设置EditText的 android:textCursorDrawable="@drawable/edit_cursor_color"
et_day.addTextChangedListener(newTextWatcher() { @Override publicvoid beforeTextChanged (CharSequence s,int start, int count, int after) { } @Override public void onTextChanged (CharSequence s, intstart,int before, int count){ if (s.length() == 2) { //限定2个字符 et_hour.requestFocus(); } } @Override public void afterTextChanged (Editable s){ } });<?xml version="1.0"encoding="utf-8"?> onFocusChange(et_reply_content.isFocused()); privatevoid onFocusChange(boolean hasFocus) { final boolean isFocus = hasFocus; new Handler().postDelayed(new Runnable() { public void run() { InputMethodManager imm =(InputMethodManager) et_reply_content.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (isFocus) { imm.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS); } else { imm.hideSoftInputFromWindow(et_reply_content.getWindowToken(), 0); } } }, 100); }
5、点击EditText要输入时,防止布局被顶上去:
解决办法:
在mainfest.xml中,对那个Activity加:
<activity android:name=".activity.HomeActivity"Android
4000
:windowSoftInputMode="adjustPan|stateHidden"></activity>
6、PopupWindowpop_reply中有EditText et_reply,防止EditText被输入法盖住:
(1)pop_reply.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
(2)、//获取焦点
onFocusChange(et_reply_content.isFocused()); privatevoid onFocusChange(boolean hasFocus) { final boolean isFocus = hasFocus; new Handler().postDelayed(new Runnable() { public void run() { InputMethodManager imm =(InputMethodManager) et_reply_content.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (isFocus) { imm.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS); } else { imm.hideSoftInputFromWindow(et_reply_content.getWindowToken(), 0); } } }, 100); }
7、//搜索页面中键盘搜索键的监听
解决办法:
private void initEditTextSearch(){
et_search.setOnEditorActionListener(newTextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextViewtextView, int actionId, KeyEvent keyEvent) {
if (actionId ==EditorInfo.IME_ACTION_SEARCH){
Log.e("ssss", "搜索");
//调用搜索的方法
return true;
}
return false;
}
});
}
8、android如何让输入框不能输入0:
解决办法:
EditTextView里有个属性,可以指定输入的值
android:digits="123456789" 表示可允许输入123456789
以上是我在开发时候遇到的问题,有问题欢迎指出,谢谢
相关文章推荐
- Liferay开发过程中的一些常见问题
- Liferay开发过程中的一些常见问题
- Android Studio开发环境配置过程中的一些常见问题
- Liferay 6.1 开发过程中的一些常见问题
- Liferay 6.1开发学习(十八):Liferay开发过程中的一些常见问题
- Liferay开发过程中的一些常见问题
- 嵌入式开发过程中烧写uboot和内核一些问题
- ArcGIS Engine 10开发环境的一些常见问题
- 一些开发中常见的简单问题
- Vue2.0总结———vue使用过程常见的一些问题
- 开发过程常见问题整理
- JS 开发过程中遇到的常见问题
- java web开发过程常见问题总结
- android开发过程中遇到的一些问题汇总
- CUnit开发环境搭建过程可能遇到的一些问题及解决方法
- eclipse 开发过程中经常出现一些UI的问题弹框
- Android开发由eclipse转Android Studio中一些常见出错问题解决方法
- [全程建模]全程建模/软件开发过程中的几个常见问题对话
- 开发过程一些问题总结
- (持续更新)日积月累——iOS开发过程中遇到的一些小问题