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;
解决办法:
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){
}
});
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){
}
});
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: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