Skip to content

Commit 407ac31

Browse files
committed
Release v1.1.6
- Fix layout issue for first selected item - Check if spinner is disabled before call performClick() - Add new attrs and method to update search text color, search hint color and search background
1 parent 8a8d022 commit 407ac31

File tree

8 files changed

+99
-11
lines changed

8 files changed

+99
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The best Android spinner library for your android application with more customiz
113113

114114
```gradle
115115
dependencies {
116-
implementation 'com.github.chivorns:smartmaterialspinner:1.1.5'
116+
implementation 'com.github.chivorns:smartmaterialspinner:1.1.6'
117117
}
118118
```
119119

resources/src/main/res/layout/smart_material_spinner_sample_layout.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
app:smsp_multilineError="true"
2525
app:smsp_searchHeaderBackgroundColor="@color/smsp_search_header_background"
2626
app:smsp_searchHeaderText="Search/Select Province"
27-
app:smsp_searchHeaderTextColor="#ffff" />
27+
app:smsp_searchHeaderTextColor="#ffff"
28+
app:smsp_searchHintColor="@color/search_hint_color"
29+
app:smsp_searchTextColor="@color/search_text_color" />
2830

2931
<TextView
3032
style="@style/headerTextStyle"

resources/src/main/res/values/colors.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
<color name="custom_item_list_color">#3F51B5</color>
1414
<color name="custom_selected_item_color">#E91E63</color>
1515
<color name="error_color">#9C27B0</color>
16+
17+
<color name="search_hint_color">#F00051</color>
18+
<color name="search_text_color">#8300D6</color>
1619
</resources>

smartmaterialspinner/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ext {
55
LIBRARY_NAME = 'SmartMaterialSpinner'
66
PUBLISH_GROUP_ID = 'com.github.chivorns'
77
PUBLISH_ARTIFACT_ID = LIBRARY_NAME.toLowerCase()
8-
PUBLISH_VERSION = '1.1.5'
8+
PUBLISH_VERSION = '1.1.6'
99

1010
// Bintray
1111
BINTRAY_REPO = 'maven'
@@ -32,7 +32,7 @@ android {
3232
defaultConfig {
3333
minSdkVersion 14
3434
targetSdkVersion 28
35-
versionCode 20
35+
versionCode 21
3636
versionName "$PUBLISH_VERSION"
3737

3838
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

smartmaterialspinner/src/main/java/com/chivorn/smartmaterialspinner/SearchableSpinnerDialog.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ public class SearchableSpinnerDialog extends DialogFragment implements SearchVie
3737
private ViewGroup searchHeaderView;
3838
private AppCompatTextView tvSearchHeader;
3939
private SearchView searchView;
40+
private TextView tvSearch;
4041
private ListView searchListView;
4142
private TextView tvListItem;
4243

4344
private boolean isEnableSearchHeader = true;
4445
private int headerBackgroundColor;
4546
private Drawable headerBackgroundDrawable;
47+
48+
private int searchBackgroundColor;
49+
private Drawable searchBackgroundDrawable;
50+
private int searchHintColor;
51+
private int searchTextColor;
52+
4653
private int searchListItemColor;
4754
private int selectedSearchItemColor;
4855
private int selectedPosition = -1;
@@ -129,6 +136,7 @@ private void initSearchDialog(View rootView, Bundle savedInstanceState) {
129136
searchHeaderView = rootView.findViewById(R.id.search_header_layout);
130137
tvSearchHeader = rootView.findViewById(R.id.tv_search_header);
131138
searchView = rootView.findViewById(R.id.search_view);
139+
tvSearch = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
132140
searchListView = rootView.findViewById(R.id.search_list_item);
133141

134142
if (getActivity() != null) {
@@ -216,6 +224,21 @@ private void initSearchBody() {
216224
if (searchHint != null) {
217225
searchView.setQueryHint(searchHint);
218226
}
227+
if (searchBackgroundColor != 0) {
228+
searchView.setBackgroundColor(searchBackgroundColor);
229+
} else if (searchBackgroundDrawable != null) {
230+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
231+
searchView.setBackground(searchBackgroundDrawable);
232+
}
233+
}
234+
if (tvSearch != null) {
235+
if (searchTextColor != 0) {
236+
tvSearch.setTextColor(searchTextColor);
237+
}
238+
if (searchHintColor != 0) {
239+
tvSearch.setHintTextColor(searchHintColor);
240+
}
241+
}
219242
}
220243

221244
@Override
@@ -298,10 +321,29 @@ public void setSearchHeaderBackgroundColor(Drawable drawable) {
298321
headerBackgroundColor = 0;
299322
}
300323

324+
public void setSearchBackgroundColor(int color) {
325+
searchBackgroundColor = color;
326+
searchBackgroundDrawable = null;
327+
}
328+
329+
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
330+
public void setSearchBackgroundColor(Drawable drawable) {
331+
searchBackgroundDrawable = drawable;
332+
searchBackgroundColor = 0;
333+
}
334+
301335
public void setSearchHint(String searchHint) {
302336
this.searchHint = searchHint;
303337
}
304338

339+
public void setSearchTextColor(int color) {
340+
searchTextColor = color;
341+
}
342+
343+
public void setSearchHintColor(int color) {
344+
searchHintColor = color;
345+
}
346+
305347
public void setSearchListItemColor(int searchListItemColor) {
306348
this.searchListItemColor = searchListItemColor;
307349
}

smartmaterialspinner/src/main/java/com/chivorn/smartmaterialspinner/SmartMaterialSpinner.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ public class SmartMaterialSpinner<T> extends AppCompatSpinner implements Adapter
141141
private int itemColor;
142142
private int itemListColor;
143143
private int selectedItemListColor;
144+
private int searchHintColor;
145+
private int searchTextColor;
144146
private float hintSize;
145147
private CharSequence floatingLabelText;
146148
private float floatingLabelSize;
@@ -271,6 +273,9 @@ private void initAttributes(Context context, AttributeSet attrs) {
271273
setSearchHeaderBackgroundColor(typedArray.getColor(R.styleable.SmartMaterialSpinner_smsp_searchHeaderBackgroundColor, ContextCompat.getColor(context, R.color.smsp_search_header_background)));
272274
}
273275
searchHint = typedArray.getString(R.styleable.SmartMaterialSpinner_smsp_searchHint);
276+
searchHintColor = typedArray.getColor(R.styleable.SmartMaterialSpinner_smsp_searchHintColor, 0);
277+
searchTextColor = typedArray.getColor(R.styleable.SmartMaterialSpinner_smsp_searchTextColor, 0);
278+
274279
//isEnableDefaultSelect = typedArray.getBoolean(R.styleable.SmartMaterialSpinner_smsp_enableDefaultSelect, true);
275280
isReSelectable = typedArray.getBoolean(R.styleable.SmartMaterialSpinner_smsp_isReSelectable, false);
276281

@@ -292,6 +297,8 @@ private void configSearchableDialog() {
292297
setSearchHint(searchHint);
293298
setSearchListItemColor(itemListColor);
294299
setSelectedSearchItemColor(selectedItemListColor);
300+
setSearchHintColor(searchHintColor);
301+
setSearchTextColor(searchTextColor);
295302
}
296303

297304
private void removeDefaultSelector(Drawable drawable) {
@@ -1365,6 +1372,21 @@ public String getSearchHint() {
13651372
return searchHint;
13661373
}
13671374

1375+
public void setSearchBackgroundColor(int color) {
1376+
if (searchableSpinnerDialog != null) {
1377+
searchableSpinnerDialog.setSearchBackgroundColor(color);
1378+
}
1379+
invalidate();
1380+
}
1381+
1382+
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
1383+
public void setSearchBackgroundColor(Drawable drawable) {
1384+
if (searchableSpinnerDialog != null) {
1385+
searchableSpinnerDialog.setSearchBackgroundColor(drawable);
1386+
}
1387+
invalidate();
1388+
}
1389+
13681390
public void setSearchHint(String searchHint) {
13691391
this.searchHint = searchHint;
13701392
if (searchableSpinnerDialog != null) {
@@ -1373,6 +1395,22 @@ public void setSearchHint(String searchHint) {
13731395
invalidate();
13741396
}
13751397

1398+
public void setSearchTextColor(int color) {
1399+
this.searchTextColor = color;
1400+
if (searchableSpinnerDialog != null) {
1401+
searchableSpinnerDialog.setSearchTextColor(color);
1402+
}
1403+
invalidate();
1404+
}
1405+
1406+
public void setSearchHintColor(int color) {
1407+
this.searchHintColor = color;
1408+
if (searchableSpinnerDialog != null) {
1409+
searchableSpinnerDialog.setSearchHintColor(color);
1410+
}
1411+
invalidate();
1412+
}
1413+
13761414
public void setSearchListItemColor(int searchListItemColor) {
13771415
if (searchableSpinnerDialog != null) {
13781416
searchableSpinnerDialog.setSearchListItemColor(searchListItemColor);

smartmaterialspinner/src/main/res/layout/smart_material_spinner_searchable_dialog_layout.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent"
56
android:orientation="vertical">
@@ -26,23 +27,23 @@
2627
<LinearLayout
2728
android:layout_width="match_parent"
2829
android:layout_height="wrap_content"
29-
android:orientation="vertical"
30-
android:paddingStart="8dp"
31-
android:paddingEnd="8dp"
32-
android:paddingBottom="8dp">
30+
android:orientation="vertical">
3331

3432
<android.support.v7.widget.SearchView
3533
android:id="@+id/search_view"
3634
android:layout_width="match_parent"
3735
android:layout_height="wrap_content"
38-
android:iconifiedByDefault="false"
39-
android:queryHint="Search..." />
36+
app:iconifiedByDefault="false"
37+
app:queryHint="Search..." />
4038

4139
<ListView
4240
android:id="@+id/search_list_item"
4341
android:layout_width="match_parent"
4442
android:layout_height="wrap_content"
43+
android:layout_marginStart="5dp"
44+
android:layout_marginEnd="5dp"
4545
android:divider="@null"
46-
android:dividerHeight="0dp" />
46+
android:dividerHeight="0dp"
47+
android:paddingBottom="5dp" />
4748
</LinearLayout>
4849
</LinearLayout>

smartmaterialspinner/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<attr name="smsp_searchHeaderTextColor" format="color|reference" />
1616
<attr name="smsp_searchHeaderBackgroundColor" format="color|reference" />
1717
<attr name="smsp_searchHint" format="string" />
18+
<attr name="smsp_searchHintColor" format="color" />
19+
<attr name="smsp_searchTextColor" format="color" />
1820

1921
<attr name="smsp_itemSize" format="dimension" />
2022
<attr name="smsp_itemColor" format="color|reference" />

0 commit comments

Comments
 (0)