Skip to content

Commit

Permalink
hint and icon customization
Browse files Browse the repository at this point in the history
  • Loading branch information
kojofosu committed Jul 27, 2021
1 parent 28e6bbe commit 835a912
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ allprojects {
dependencies {
//implementation 'com.github.iammert:MultiSearchView:0.3'
implementation 'com.github.kojofosu:MultiSearchView:0.7'
implementation 'com.github.kojofosu:MultiSearchView:0.8'
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.iammert.library.ui.multisearchview

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.annotation.ColorInt
import androidx.core.content.res.ResourcesCompat
import androidx.databinding.DataBindingUtil
import com.iammert.library.ui.multisearchview.databinding.ActivityMainBinding
import com.iammert.library.ui.multisearchviewlib.MultiSearchView
Expand All @@ -14,6 +17,8 @@ class MainActivity : AppCompatActivity() {
val binding: ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)

binding.multiSearchView.hint = "What are you looking for?"
binding.multiSearchView.setHintColor("#f0cc1e")
binding.multiSearchView.setSearchIconColor(R.color.colorAccent)

binding.multiSearchView.setSearchViewListener(object : MultiSearchView.MultiSearchViewListener{
override fun onItemSelected(index: Int, s: CharSequence) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.iammert.library.ui.multisearchviewlib
import android.animation.LayoutTransition
import android.animation.ValueAnimator
import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
Expand All @@ -28,6 +29,8 @@ class MultiSearchContainerView @JvmOverloads constructor(

var hintColor: Int? = null

var hintColorStateList: ColorStateList? = null

var selectedTabStyle = 0

var searchTextStyle = 0
Expand Down Expand Up @@ -195,7 +198,14 @@ class MultiSearchContainerView @JvmOverloads constructor(
val viewItem: ViewItemBinding = context.inflate(R.layout.view_item)

viewItem.editTextSearch.hint = hint
hintColor?.let { viewItem.editTextSearch.setHintTextColor(it) }

if (hintColorStateList != null)
viewItem.editTextSearch.setHintTextColor(hintColorStateList)

if (hintColor != null)
viewItem.editTextSearch.setHintTextColor(hintColor as Int)


viewItem.editTextSearch.setStyle(context, searchTextStyle)

viewItem.root.layoutParams = LinearLayout.LayoutParams(searchViewWidth.toInt(), WRAP_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ class MultiSearchView @JvmOverloads constructor(context: Context, attrs: Attribu
binding.searchViewContainer.hint = value
}

var hintColor : Int?
get() = binding.searchViewContainer.hintColor
set(value) {
binding.searchViewContainer.hintColor = value
}
init {
val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.MultiSearchView, defStyleAttr, defStyleAttr)
val searchTextStyle = typedArray.getResourceId(R.styleable.MultiSearchView_searchTextStyle, 0)
Expand Down Expand Up @@ -80,6 +75,16 @@ class MultiSearchView @JvmOverloads constructor(context: Context, attrs: Attribu
binding.imageViewSearch.setImageResource(drawable)
}

fun setHintColor(colorString: String) {
val colorInt = Color.parseColor(colorString)
binding.searchViewContainer.hintColor = colorInt
}

fun setHintColor(color: Int) {
val colorStateList = AppCompatResources.getColorStateList(context, color)
binding.searchViewContainer.hintColorStateList = colorStateList
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun setSearchIconColor(color : Int) {
binding.imageViewSearch.imageTintList = AppCompatResources.getColorStateList(context, color)
Expand Down
9 changes: 9 additions & 0 deletions multisearchviewlib/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>

<color name="blueGrey">#90A4AE</color>
<color name="custom_purple">#6621E1</color>
</resources>

0 comments on commit 835a912

Please sign in to comment.