开发过程中,EditText的一些常见问题

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




以上是我在开发时候遇到的问题,有问题欢迎指出,谢谢


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值