状态为Android中不为空的EditText

时间:2017-08-02 14:16:56

标签: android android-edittext state

我将此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不为空的状态(用户在其中写了一些内容)?

2 个答案:

答案 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
}