Change border color when edittext is focused

前端 未结 1 897
清酒与你
清酒与你 2020-12-01 17:06

I am wondering how I can change the border color of the edittext when it is focused, at the moment it looks like this:

1条回答
  •  甜味超标
    2020-12-01 17:29

    You can create a custom shape for your EditText

    1: STATE_ENABLED is to check if the ET is enabled/disabled.

    2: STATE_PRESSED is to check when the ET is pressed (it will change the color on the press but won't keep it that way.)

    3: STATE_FOCUSED keeps the ET border color changed as long as the ET is focused(This fulfills the requirement).

    
        
            
                
                
                
            
        
        
            
                
                
            
        
    
    

    And set background:

    editText.setBackgroundResource(R.drawable.yourFile);
    

    0 讨论(0)
提交回复
热议问题