zoukankan      html  css  js  c++  java
  • Android Edittext 显示光标 获取焦点 监听焦点

    Android Edittext 显示光标 获取焦点 监听焦点   



    Edittext java 代码控制获取焦点  
                EditText mEditText = (EditText) findViewById(R.id.et);
                mEditText.setFocusable(true);
                mEditText.setFocusableInTouchMode(true);

    显示光标
    mEditText.requestFocus();//获取焦点 光标出现

    失去焦点
    mEditText.clearFocus();
    监听EditText焦点变化   当获取焦点后 hasFocus 为true
    mEditText.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
    
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
    
                        if (hasFocus) {
    
                            // 获得焦点
    
                        } else {
    
                            // 失去焦点
    
                        }
    
                    }
    
    
                });


    使用XML配置文件控制光标的代码
    cursorVisible 中
    true为显示  
    false为隐藏光标
    android:cursorVisible="true"
    android:cursorVisible="false"

    EditText不自己主动获取焦点 在EditText的父级控件上设置
                        android:focusable="true"
                        android:focusableInTouchMode="true"

    EditText 设置光标颜色
                    android:textCursorDrawable="#ff2244"
    
    假设想设置光标颜色和字体一样 设置@null 就可以


    //  ┏┓   ┏┓
    //┏┛┻━━━┛┻┓
    //┃       ┃
    //┃   ━   ┃
    //┃ ┳┛ ┗┳ ┃
    //┃       ┃
    //┃   ┻   ┃
    //┃       ┃
    //┗━┓   ┏━┛
    //    ┃   ┃   神兽保佑
    //    ┃   ┃   代码无BUG!
    //    ┃   ┗━━━┓
    //    ┃       ┣┓
    //    ┃       ┏┛
    //    ┗┓┓┏━┳┓┏┛
    //      ┃┫┫ ┃┫┫
    //      ┗┻┛ ┗┻┛

    希望对大家实用

  • 相关阅读:
    hdu1698(线段树)
    poj3468(线段树)
    hdu1394(线段树求逆序对)
    hdu1754(线段树)
    hdu1166(线段树)
    hdu2412(树形dp)
    hdu4714(树形dp)
    hdu4705(树形dp)
    hdu4679(树形dp)
    滑动导航条
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/7270459.html
Copyright © 2011-2022 走看看