2017-08-02 43 views
0

不是空的EditText我用这个selectorEditText国家在Android电子

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" android:drawable="@drawable/mostatil" /><!-- user tap on edit text --> 
    <item android:state_focused="false" android:drawable="@drawable/mostatil50" /><!-- user didn't tap or tap another edit text --> 
    <!-- state for not empty edit text --> 
</selector> 

是否有EditText显示EditText任何状态不为空(用户写了一些东西)?

回答

0
/Just use the below code Snippet/ 

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/mostatil50" android:state_pressed="true" /> 
    <item android:drawable="@drawable/mostatil" android:state_focused="true" /> 
    <item android:drawable="@drawable/mostatil" /> 

</selector> 
+0

感谢,但它并没有通过代码工作 – Fanous

0

你可以检查的EditText是使用下面的代码空:

EditText edittext = (EditText)findViewById(R.id.edittext); 
edittext = edittext.getText().toString(); 
if (edittext.matches("")) { 
    //do something here 
} 
else { 
    //do something else 
} 
+0

感谢,我要补充的侦听器的所有其他项目在布局中检测任何变化。如果存在这种情况的状态...... – Fanous

+0

当然,对于其他与文本相关的元素,您可以使用类似的侦听器。但是,对于与焦点,按下,激活等相关的状态更改,您可以直接使用XML代码。 – Abhi

+0

如果这个或其他答案解决了这个问题,请考虑接受它。 – Abhi