android之EditText文本监听(addTextChangedListener)

阅读更多
直接贴代码吧      
_ok.setClickable(false); // 初始化不可点击
        _ok.setEnabled(false);
        _edit = (EditText)findViewById(R.id.fb_status_eidt);
        //主要是监听器里接口的实现
        _edit.addTextChangedListener(new TextWatcher(){
            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
           
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub
               
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub
                //关键是这里,监听输入的字符串,如果大于零,则可点击,enable.
                if(s.length()>0){
                    _ok.setClickable(true);
                    _ok.setEnabled(true);
                }else{
                    _ok.setClickable(false);
                    _ok.setEnabled(false);
                }
            }
        });

下面是selector(btn_bg_ok.xml)的内容,不同状态下,button的颜色不同


   
   
   
     
     
   


button关联btn_bg_ok.xml

你可能感兴趣的:(Android,XML)