From 88466f714134c79567487294db6e931d4ca8874f Mon Sep 17 00:00:00 2001 From: pichs Date: Thu, 4 Mar 2021 22:55:43 +0800 Subject: [PATCH] XCheckBox --- app/build.gradle | 1 + .../com/pichs/app/xwidget/MainActivity.java | 28 ++ app/src/main/res/layout/activity_main.xml | 55 +++- .../common/widget/checkbox/XCheckBox.java | 115 ++++++++ .../common/widget/input/InputLayout.java | 53 ++-- .../common/widget/utils/XGradientHelper.java | 245 ++---------------- widget/src/main/res/values/attrs.xml | 7 + 7 files changed, 233 insertions(+), 271 deletions(-) create mode 100644 widget/src/main/java/com/pichs/common/widget/checkbox/XCheckBox.java diff --git a/app/build.gradle b/app/build.gradle index 333860f..07c23d9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,4 +38,5 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation project(':widget') + implementation 'com.github.xujiaji:ripple-checkbox:0.0.5' } \ No newline at end of file diff --git a/app/src/main/java/com/pichs/app/xwidget/MainActivity.java b/app/src/main/java/com/pichs/app/xwidget/MainActivity.java index 04054e9..9e23336 100644 --- a/app/src/main/java/com/pichs/app/xwidget/MainActivity.java +++ b/app/src/main/java/com/pichs/app/xwidget/MainActivity.java @@ -5,14 +5,18 @@ import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.Typeface; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.view.View; import android.widget.Button; +import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import com.pichs.common.widget.cardview.XCardButton; +import com.pichs.common.widget.checkbox.XCheckBox; import com.pichs.common.widget.switcher.XSwitchButton; import com.pichs.common.widget.utils.XStatusBarHelper; import com.pichs.common.widget.utils.XTypefaceHelper; @@ -28,8 +32,32 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); XCardButton btn = findViewById(R.id.btn1); + XCheckBox checkbox = findViewById(R.id.checkbox); + checkbox.setOnCheckedChangeListener(new XCheckBox.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(boolean isChecked) { + Toast.makeText(getApplicationContext(), "ischecked:" + isChecked, Toast.LENGTH_LONG).show(); + } + }); + + XSwitchButton swb = findViewById(R.id.swb); + swb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + checkbox.setImageDrawable(new ColorDrawable(Color.BLACK)); + checkbox.setCheckedDrawable(new ColorDrawable(Color.RED)); + + } else { + checkbox.setImageDrawable(new ColorDrawable(Color.GREEN)); + checkbox.setCheckedDrawable(new ColorDrawable(Color.BLUE)); + + } + + } + }); swb.setThumbColor(Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK); swb.setBackgroundColor(Color.GREEN, Color.CYAN); btn.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8de5168..a7f05d4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,8 +22,8 @@ + android:layout_height="wrap_content" + android:background="#0ff"> + + + + android:layout_height="80dp" + android:background="#D1EFE3" + android:orientation="vertical"> + + + + + + + + + + android:layout_height="wrap_content" + android:hint="师范生克拉夫" /> + + + + + + + \ No newline at end of file