RadioButton自定义、EditText输入状态监听

2019-10-20  本文已影响0人  流苏丶
xml代码:
        <RadioButton
                android:id="@id/radio_button"
                android:layout_width="165dp"
                android:layout_height="30dp"
                style="@style/CustomRadioBtn"
                android:checked="true" />
CustomRadioBtn:
<style name="CustomRadioBtn"> 
        <item name="android:gravity">center</item>
        <item name="android:background">@drawable/radiobutton_background</item> 
        <item name="android:button">@null</item> 
</style>
radiobutton_background:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- RadioButton 动态改变背景色 -->
    <item android:drawable="@drawable/radiobutton_background_checked" android:state_checked="true" />
    <!-- not selected -->
    <item android:drawable="@drawable/radiobutton_background_unchecked" android:state_checked="false" />
</selector>
radiobutton_background_checked:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- 填充 -->
    <solid android:color="@color/black" />
    <!-- 圆角 -->
    <corners android:radius="5dp" />
</shape>
radiobutton_background_unchecked:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- 填充 -->
    <solid android:color="@color/grey" />
    <!-- 圆角 -->
    <corners android:radius="5dp" />
</shape>

EditText输入状态监听

editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (TextUtils.isEmpty(editText.getText())){
                    //如果为空
                    nextButton.setEnabled(false);
                }else {
                    nextButton.setEnabled(true);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
上一篇 下一篇

猜你喜欢

热点阅读