美文网首页
RadioButton自定义、EditText输入状态监听

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

作者: 流苏丶 | 来源:发表于2019-10-20 11:56 被阅读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) {
    
                }
            });
    

    相关文章

      网友评论

          本文标题:RadioButton自定义、EditText输入状态监听

          本文链接:https://www.haomeiwen.com/subject/ylgomctx.html