王学岗RadioGroup设置某个Item没有点击效果

有这样的一个需求,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">

        <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没有改变背景颜色

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值