Skip to content

Commit

Permalink
Implement spinner_color attribute for changing spinner color
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Mar 6, 2020
1 parent 77eb1aa commit 0925bdf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity" />
<activity android:name=".CustomActivity">
<activity android:name=".CustomActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ 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
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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -187,6 +194,7 @@ class ExpandableLayout : FrameLayout {
if (spinnerDrawable != null) {
setImageDrawable(spinnerDrawable)
}
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(spinnerColor))
if (showSpinner) {
visible(true)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<attr name="expandable_spinner_rotation" format="integer" />
<attr name="expandable_spinner_size" format="dimension" />
<attr name="expandable_spinner_margin" format="dimension" />
<attr name="expandable_spinner_color" format="color" />
<attr name="expandable_animation" format="enum">
<enum name="normal" value="0" />
<enum name="accelerate" value="1" />
Expand Down

0 comments on commit 0925bdf

Please sign in to comment.