当页面所有edittext不为空时按钮才可点击。
activity实现TextWatcher接口,oncreate方法添加输入框监听
ed1.addTextChangedListener(this); ed2.addTextChangedListener(this); ed3.addTextChangedListener(this);
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (StringUtils.isNotEmpty(ed1.getText().toString()) && StringUtils.isNotEmpty(ed2.getText().toString()) && StringUtils.isNotEmpty(ed3.getText().toString())) { okBtn.setEnabled(true); } else { okBtn.setEnabled(false); } }
为区分按钮状态设置enable=false背景为灰色android:background="@drawable/button_activity"
button_activity.xml文件
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape> <solid android:color="@color/programstatus_review" /> <stroke android:width="2dp" android:color="@color/lottery_button" /> <corners android:radius="15dp" /> </shape></item> <item android:state_enabled="false"><shape> <stroke android:width="2dp" /> <solid android:color="@color/c_gray_light" /> <corners android:radius="15dp" /> <padding android:bottom="5dp" android:left="20dp" android:right="20dp" android:top="5dp" /> </shape></item> <item><shape> <stroke android:width="2dp" /> <solid android:color="@color/c_gray_1" /> <corners android:radius="15dp" /> <padding android:bottom="5dp" android:left="20dp" android:right="20dp" android:top="5dp" /> </shape></item> </selector>