点击变复选框

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//布局-----------------------------------------------------
<?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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值