有趣的checkbox动画切换状态(支付宝转账成功显示)--第三方开源--AnimCheckBox

这个很有趣的指标通过AnimCheckBox实现,下载地址:https://github.com/lguipeng/AnimCheckBox

代码:

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- app:circle_color 点击后的背景颜色设置 -->
    <!-- app:stroke_color 线条颜色和点击后的勾勾颜色设置 -->
    <!-- app:stroke_width  线条宽度设置 -->

    <com.github.lguipeng.library.animcheckbox.AnimCheckBox
        android:id="@+id/checkBox"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true"
        app:circle_color="#1976D2"
        app:stroke_width="4dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/checkBox"
        android:layout_centerHorizontal="true"
        android:paddingTop="20dp"
        android:text="button" />

</RelativeLayout>

MainActivity.java:


package com.zzw.testanimcheckbox;

import com.github.lguipeng.library.animcheckbox.AnimCheckBox;
import com.github.lguipeng.library.animcheckbox.AnimCheckBox.OnCheckedChangeListener;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class MainActivity extends Activity {
    private  boolean temp=true;
    private  AnimCheckBox checkBox;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        checkBox = (AnimCheckBox) findViewById(R.id.checkBox);
        // 设置默认显示为勾还是圈
        checkBox.setChecked(temp);

        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onChange(boolean checked) {
                if(checked==true){
                    Toast.makeText(getApplicationContext(), "true", 0).show();
                }else{
                    Toast.makeText(getApplicationContext(), "false", 0).show();
                }
            }
        });
        findViewById(R.id.button).setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                if(temp==true){
                    temp=false;
                }else{
                    temp=true;
                }
                //当点击按钮判断值temp变化了的时候,checkBox的随之变化,并且显示出动画效果,
                //后面如果是false的话,动画就不会显示,并且画面不会出现变化
                checkBox.setChecked(temp,true);
            }
        });
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值