我将此selector
用于我的EditText
:
<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 :(得分: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>
答案 1 :(得分:0)
您可以使用以下代码检查EditText是否为空:
EditText edittext = (EditText)findViewById(R.id.edittext);
edittext = edittext.getText().toString();
if (edittext.matches("")) {
//do something here
}
else {
//do something else
}