zoukankan      html  css  js  c++  java
  • Edittext 的变化监听、图片设置

    edittext的变化监听有addTextChangedListener,code:

            editText.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    if (s.length() > 5)
                        textView1.setText("大于 5");
                    else
                        textView1.setText("小于 5");
                }
            });
    

    也可以以接口的形式写入

    TextWatcher textWatcher;//定义一个watcher
    
    
     textWatcher = new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
    
                }
    
                @Override
                public void afterTextChanged(Editable s) {
                    if (s.length() > 5)
                        textView1.setText("大于 5");
                    else
                        textView1.setText("小于 5");
                }
            };
    
    
    
            editText.addTextChangedListener(textWatcher);
    

    动态对edittext的图片进行改变

            Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            editText.setCompoundDrawables(drawable, drawable, null, null); //四个参数代表四个位置,左上右下
    
  • 相关阅读:
    NOIP 2017逛公园(记忆化搜索)
    NOIP 2012疫情控制 (二分+倍增+贪心)
    NOIP 2005过河(DP+路径压缩)
    P1198 [JSOI2008]最大数
    [Noip2016]蚯蚓
    [六省联考2017]期末考试
    六省联考:组合数问题
    蒜头君的兔子
    bzoj1015 [JSOI2008]星球大战starwar
    luogu P3370 【模板】字符串哈希
  • 原文地址:https://www.cnblogs.com/lyxin/p/5872263.html
Copyright © 2011-2022 走看看