From 0925bdf2b7555ed1143b0323ccc3bef045cd9fca Mon Sep 17 00:00:00 2001 From: skydoves Date: Fri, 6 Mar 2020 21:20:31 +0900 Subject: [PATCH] Implement spinner_color attribute for changing spinner color --- app/src/main/AndroidManifest.xml | 4 ++-- .../com/skydoves/expandablelayoutdemo/CustomActivity.kt | 2 +- app/src/main/res/layout/activity_main.xml | 3 ++- .../com/skydoves/expandablelayout/ExpandableLayout.kt | 8 ++++++++ .../src/main/res/values/attrs_expandablelayout.xml | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 00f7722..ff6e6ca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,8 +11,8 @@ android:supportsRtl="true" android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning"> - - + + diff --git a/app/src/main/java/com/skydoves/expandablelayoutdemo/CustomActivity.kt b/app/src/main/java/com/skydoves/expandablelayoutdemo/CustomActivity.kt index 7c9e210..9dde199 100644 --- a/app/src/main/java/com/skydoves/expandablelayoutdemo/CustomActivity.kt +++ b/app/src/main/java/com/skydoves/expandablelayoutdemo/CustomActivity.kt @@ -22,7 +22,7 @@ import kotlinx.android.synthetic.main.activity_custom.* class CustomActivity : AppCompatActivity() { - private val adapter by lazy { ParentAdapter() } + private val adapter = ParentAdapter() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1ca50cb..ef0d96b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -36,5 +36,6 @@ app:expandable_duration="200" app:expandable_isExpanded="false" app:expandable_parentLayout="@layout/layout_parent2" - app:expandable_secondLayout="@layout/layout_second2" /> + app:expandable_secondLayout="@layout/layout_second2" + app:expandable_spinner_color="@color/md_amber_700" /> \ No newline at end of file diff --git a/expandablelayout/src/main/java/com/skydoves/expandablelayout/ExpandableLayout.kt b/expandablelayout/src/main/java/com/skydoves/expandablelayout/ExpandableLayout.kt index f159f61..5272762 100644 --- a/expandablelayout/src/main/java/com/skydoves/expandablelayout/ExpandableLayout.kt +++ b/expandablelayout/src/main/java/com/skydoves/expandablelayout/ExpandableLayout.kt @@ -18,7 +18,9 @@ package com.skydoves.expandablelayout import android.animation.ValueAnimator import android.content.Context +import android.content.res.ColorStateList import android.content.res.TypedArray +import android.graphics.Color import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.LayoutInflater @@ -26,8 +28,10 @@ import android.view.View import android.view.ViewGroup import android.widget.FrameLayout import android.widget.RelativeLayout +import androidx.annotation.ColorInt import androidx.annotation.LayoutRes import androidx.annotation.Px +import androidx.core.widget.ImageViewCompat import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.expandable_layout_parent.view.arrow import kotlinx.android.synthetic.main.expandable_layout_parent.view.cover @@ -77,6 +81,7 @@ class ExpandableLayout : FrameLayout { var spinnerRotation: Int = -180 var spinnerAnimate: Boolean = true var onExpandListener: OnExpandListener? = null + @ColorInt var spinnerColor: Int = Color.WHITE constructor(context: Context) : super(context) @@ -143,6 +148,8 @@ class ExpandableLayout : FrameLayout { a.getDimension(R.styleable.ExpandableLayout_expandable_spinner_size, this.spinnerSize) this.spinnerMargin = a.getDimension(R.styleable.ExpandableLayout_expandable_spinner_margin, this.spinnerMargin) + this.spinnerColor = + a.getColor(R.styleable.ExpandableLayout_expandable_spinner_color, this.spinnerColor) this.isExpanded = a.getBoolean(R.styleable.ExpandableLayout_expandable_isExpanded, this.isExpanded) } @@ -187,6 +194,7 @@ class ExpandableLayout : FrameLayout { if (spinnerDrawable != null) { setImageDrawable(spinnerDrawable) } + ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(spinnerColor)) if (showSpinner) { visible(true) } else { diff --git a/expandablelayout/src/main/res/values/attrs_expandablelayout.xml b/expandablelayout/src/main/res/values/attrs_expandablelayout.xml index ed5eb72..2a93e32 100644 --- a/expandablelayout/src/main/res/values/attrs_expandablelayout.xml +++ b/expandablelayout/src/main/res/values/attrs_expandablelayout.xml @@ -11,6 +11,7 @@ +