有这样的一个需求,RadioGroup包含若干个RadioButton默认每个RadioButton都有点击变色的效果。但是指定一个RadioButton没有点击变色的效果,但是依旧能接收点击事件。先看下布局

<RadioGroup
        android:id="@+id/game_count_rb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"&gt;

        <RadioButton
            android:id="@+id/home_today_game_count_rb"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/home_bet_type_bg_selector"
            android:button="@null"
            android:checked="true"
            android:gravity="center"
            android:lineSpacingMultiplier="1.2"
            android:textColor="@color/bet_type_text_color"
            android:textSize="@dimen/sp_12"
            tools:text="今日n619" />

        <RadioButton
            android:id="@+id/home_roll_ball_count_rb"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/home_bet_type_bg_selector"
            android:button="@null"
            android:gravity="center"
            android:lineSpacingMultiplier="1.2"
            android:textColor="@color/bet_type_text_color"
            android:textSize="@dimen/sp_12"
            tools:text="滚球n619" />

        <RadioButton
            android:id="@+id/home_morning_trade_count_rb"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/home_bet_type_bg_selector"
            android:button="@null"
            android:gravity="center"
            android:lineSpacingMultiplier="1.2"
            android:textColor="@color/bet_type_text_color"
            android:textSize="@dimen/sp_12"
            tools:text="早盘n619" />

        <RadioButton
            android:id="@+id/home_serial_pass_count_rb"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/home_bet_type_bg_selector"
            android:button="@null"
            android:gravity="center"
            android:lineSpacingMultiplier="1.2"
            android:textColor="@color/bet_type_text_color"
            android:textSize="@dimen/sp_12"
            tools:text="串关n619" />

    </RadioGroup>

bet_type_text_color文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/color_white" android:state_selected="true" />
    <item android:color="@color/color_white" android:state_checked="true" />
    <item android:color="@color/color_655b7d" />
</selector>

home_bet_type_bg_selector文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/home_icon_today_bg" android:state_selected="true" />
    <item android:drawable="@drawable/home_icon_today_bg" android:state_checked="true" />
    <item android:drawable="@drawable/home_icon_roll_ball_bg" />
</selector>

home_icon_today_bg和home_icon_roll_ball_bg是两张图片

代码中的实现

   sportRollBallCountTv.setClickable(false);
        sportRollBallCountTv.setOnTouchListener((v, event) -> {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    downTime=System.currentTimeMillis();
                    break;

                case MotionEvent.ACTION_UP:
                    if (System.currentTimeMillis()-downTime<200){
                        clickListener.onBetTypeViewClick(TYPE_ROLL_BALL);
                    }

                    break;
            }
            return true;
        });

sportRollBallCountTv就是ID为home_roll_ball_count_rb控件点击运行可以发现,有点击事件但home_roll_ball_count_rb没有改变背景颜色

原文地址:https://blog.csdn.net/qczg_wxg/article/details/125067666

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_39410.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注