点击变复选框

本文介绍了一款应用中视频屏蔽功能的用户界面设计及其实现方式。通过XML布局文件展示了具体的界面元素及其属性,包括文本标签、复选框及按钮等。同时,提供了MainActivity的代码示例,演示了如何响应用户操作并弹出包含屏蔽选项的对话框。
//布局-----------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>

    <LinearLayout
    android:orientation="vertical"
    android:background="@drawable/btn_assets_receive"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="20dp"
        android:textColor="#ff252525"
        android:text="设置屏蔽范围"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:layout_gravity="center"/>


    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

    <CheckBox
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:button="@mipmap/empty"
        android:layout_marginLeft="20dp"
        android:id="@+id/checkbox1"/>

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="17dp"
        android:layout_marginLeft="8dp"
        android:textColor="#ff4a4a4a"
        android:text="不看他的视频"/>

</LinearLayout>

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="13dp"
        android:textColor="#ff4a4a4a"
        android:text="信息流里不再显示他的视频"
        android:layout_marginLeft="44dp"/>


    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

    <CheckBox
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginTop="6dp"
        android:layout_marginLeft="20dp"
        android:button="@mipmap/empty"
        android:id="@+id/checkbox2"/>

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="17dp"
        android:textColor="#ff4a4a4a"
        android:layout_marginLeft="8dp"
        android:text="禁止他对我的视频互动"
        android:layout_marginTop="7dp"/>

</LinearLayout>

    <TextView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:textSize="13dp"
        android:textColor="#ff4a4a4a"
        android:text="他无法对我的视频评论,点赞,分享"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="44dp"/>

    <TextView
        android:background="#ccc"
        android:layout_height="1dp"
        android:layout_width="match_parent"/>


    <LinearLayout
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

    <Button
        android:background="#fff"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="18dp"
        android:textColor="#ff252525"
        android:text="取消屏蔽"
        android:layout_weight="1"/>

    <TextView
        android:layout_height="10dp"
        android:layout_width="1dp"/>

    <Button
        android:background="#fff"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="18dp"
        android:textColor="#ff252525"
        android:text="确定屏蔽"
        android:layout_weight="1"
        android:topRightRadius="13dp"/>

</LinearLayout>
</LinearLayout>




//MainActvity-------------------------------------------------------
package com.qjtc.magicalar.activity;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import com.qjtc.magicalar.R;

public class VideoActivity extends AppCompatActivity {

    private ImageView backs;
    private ImageView shield;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        backs = findViewById(R.id.backs);
        shield = findViewById(R.id.shield);
        backs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        //弹出框
        shield.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View inflate = View.inflate(VideoActivity.this, R.layout.shield_dialog, null);
                CheckBox checkBox1 = inflate.findViewById(R.id.checkbox1);
                CheckBox checkBox2 = inflate.findViewById(R.id.checkbox2);
                checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked){
                            buttonView.setButtonDrawable(R.mipmap.dui);
                        }else {
                            buttonView.setButtonDrawable(R.mipmap.empty);
                        }
                    }
                });
                checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked){
                            buttonView.setButtonDrawable(R.mipmap.dui);
                        }else {
                            buttonView.setButtonDrawable(R.mipmap.empty);
                        }
                    }
                });
                AlertDialog.Builder builder = new AlertDialog.Builder(VideoActivity.this);
                builder.setView(inflate);
                builder.create().show();
            }
        });
    }
}
//Drawlayout-------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#ffffff" />

    <corners android:radius="4dp" />

</shape>
可以使用 jQuery 或原生 JavaScript 实现点击复选框颜色的功能。 ### 使用 jQuery 实现 以下是使用 jQuery 实现点击 table 中复选框来改 tr 颜色的示例代码: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> table { border-collapse: collapse; } td { border: 1px solid #ccc; padding: 5px; } </style> </head> <body> <table> <tr> <td><input type="checkbox"></td> <td>内容1</td> </tr> <tr> <td><input type="checkbox"></td> <td>内容2</td> </tr> <tr> <td><input type="checkbox"></td> <td>内容3</td> </tr> </table> <script> $(document).ready(function () { $('input[type="checkbox"]').change(function () { var tr = $(this).closest('tr'); if ($(this).is(':checked')) { tr.css('background-color', '#f3fbff'); } else { tr.css('background-color', ''); } }); }); </script> </body> </html> ``` 在上述代码中,使用 jQuery 为所有的复选框绑定 `change` 事件,当复选框状态改时,通过 `closest` 方法找到其所在的 `tr` 元素,根据复选框是否选中来设置 `tr` 的背景颜色。 ### 使用原生 JavaScript 实现 以下是使用原生 JavaScript 实现点击表格一行中任意一行即选中该行相关复选框,同时改背景色的示例代码: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> table { border-collapse: collapse; } td { border: 1px solid #ccc; padding: 5px; } </style> </head> <body> <table> <tr> <td><input type="checkbox"></td> <td>内容1</td> </tr> <tr> <td><input type="checkbox"></td> <td>内容2</td> </tr> <tr> <td><input type="checkbox"></td> <td>内容3</td> </tr> </table> <script> function checkTr(tr) { var tds = tr.childNodes; for (var j = 0; j < tds.length; j++) { var inputs = tds[j].childNodes; for (var i = 0; i < inputs.length; i++) { if (inputs[i].type == "checkbox") { inputs[i].checked = !inputs[i].checked; tr.style.backgroundColor = inputs[i].checked ? "#f3fbff" : ""; } } } } var trs = document.getElementsByTagName('tr'); for (var k = 0; k < trs.length; k++) { trs[k].addEventListener('click', function () { checkTr(this); }); } </script> </body> </html> ``` 在上述代码中,定义了 `checkTr` 函数,用于处理点击 `tr` 时的逻辑,遍历 `tr` 中的所有 `input` 元素,找到复选框并改其选中状态,同时根据复选框状态改 `tr` 的背景颜色。然后为所有的 `tr` 元素绑定 `click` 事件,调用 `checkTr` 函数。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值