The best Android spinner library for your android application with more customization
Legacy (See usage)
AndroidX (See usage)
- Dropdown mode ( android:spinnerMode="dropdown" ). By default it is dropdown mode
- Dialog mode ( android:spinnerMode="dialog" )
- Searchable mode ( app:smsp_isSearchable="true" )
smsp_isSearchable
: Default is false. Set it to true to enable this feature.smsp_enableSearchHeader
: Default is true. Set it to false to hide search header.smsp_searchHeaderText
: Text display as header textsmsp_searchHeaderTextColor
: For changing header text colorsmsp_searchHeaderBackgroundColor
: For changing header background colorsmsp_searchHint
: To set query text hintsmsp_searchHintColor
: To set hint color to query search textsmsp_searchTextColor
: To set color to query search textsmsp_searchBackgroundColor
: To set background color to searchviewsmsp_itemListBackgroundColor
: To set background color to search item listsmsp_enableDismissSearch
: To enable/disable dismiss button on search dialogsmsp_dismissSearchText
: To set dismiss button text for search dialogsmsp_dismissSearchColor
: To set dismiss button text color for search dialog
smsp_itemSize
: To set spinner item sizesmsp_itemColor
: To set spinner item color
smsp_hint
: To set spinner hint textsmsp_hintSize
: To set spinner hint text sizesmsp_hintColor
: To set spinner hint colorsmsp_itemListHintColor
: To set spinner hint text color (dropdown hint)smsp_itemListHintBackgroundColor
: To set spinner hint background (dropdown hint)
smsp_enableFloatingLabel
: Default is true. Set it to false to disable floating label.smsp_alwaysShowFloatingLabel
: Default is false. Set it to true for always display.smsp_floatingLabelText
: Update it to what text you want. If the value is not set, it get from hint.smsp_floatingLabelSize
: For changing floating label sizesmsp_floatingLabelColor
: For changing floating label color
smsp_enableErrorLabel
: Default it is true.smsp_errorText
: Your error message text.smsp_errorTextSize
: For changing error text sizesmsp_errorTextColor
: for changing error text colorsmsp_multilineError
: Default is false. Update it to show as single line or multiple linesmsp_errorTextAlignment
: Align error text to left, center or right
- Item text color (
smsp_itemColor
) - Hint color (
smsp_hintColor
) - Floating Label color (
smsp_floatingLabelColor
) - Error Text color (
smsp_errorTextColor
) - List Item Hint color and background (
smsp_itemListHintColor
&smsp_itemListHintBackgroundColor
) - List Item color (
smsp_itemListColor
) - Selected item color (
smsp_selectedItemListColor
) - Arrow or selector color (
smsp_arrowColor
) - Underline color (
smsp_underlineColor
) - Dropdown list/Search ListView background (
smsp_itemListBackgroundColor
) - Search dialog dismiss button color (
smsp_dismissSearchColor
)
- In case if you want to design view with empty spinner and apply click event and here it is.
smsp_underlineSize
: To set underline size (The bottom line of spinner)smsp_underlineColor
: To set underline color (The bottom line of spinner)
smsp_isReSelectable
: Allow re-selectable for current selected item. By default it is false
smsp_isRtl
: To change position of view from right to left or left to right. I will update more on it.
smsp_typeface
: Apply custom font to whole spinner view. You can use this attr without specify font extensionsmsp_typeface_xxx
: Set typeface to specific part of spinner
dependencies {
implementation 'com.github.chivorns:smartmaterialspinner:1.2.1'
}
dependencies {
implementation 'com.github.chivorns.androidx:smartmaterialspinner:1.2.1'
}
<com.chivorn.smartmaterialspinner.SmartMaterialSpinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:smsp_errorText="This is error text. You can show it as single line or multiple lines using attr smsp_multilineError"
app:smsp_floatingLabelColor="#1976D2"
app:smsp_floatingLabelText="Floating Label Text"
app:smsp_hint="Hint Text"
app:smsp_hintColor="#388E3C"
app:smsp_itemColor="#512DA8"
app:smsp_itemListColor="#7C4DFF"
app:smsp_itemListHintBackgroundColor="#808080"
app:smsp_itemListHintColor="#FFFFFF"
app:smsp_multilineError="false"
app:smsp_selectedItemListColor="#FF5252" />
public class MainActivity extends AppCompatActivity {
private SmartMaterialSpinner spProvince;
private SmartMaterialSpinner spEmptyItem;
private List<String> provinceList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smart_material_spinner_sample_layout);
initSpinner();
}
private void initSpinner() {
spProvince = findViewById(R.id.sp_provinces);
spEmptyItem = findViewById(R.id.sp_empty_item);
provinceList = new ArrayList<>();
provinceList.add("Kampong Thom");
provinceList.add("Kampong Cham");
provinceList.add("Kampong Chhnang");
provinceList.add("Phnom Penh");
provinceList.add("Kandal");
provinceList.add("Kampot");
spProvince.setItem(provinceList);
spProvince.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
Toast.makeText(MainActivity.this, provinceList.get(position), Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
}
class MainActivity : AppCompatActivity() {
private var spProvince: SmartMaterialSpinner? = null
private var spEmptyItem: SmartMaterialSpinner? = null
private var provinceList: MutableList<String>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.smart_material_spinner_sample_layout)
initSpinner()
}
private fun initSpinner() {
spProvince = findViewById(R.id.sp_provinces)
spEmptyItem = findViewById(R.id.sp_empty_item)
provinceList = ArrayList()
provinceList!!.add("Kampong Thom")
provinceList!!.add("Kampong Cham")
provinceList!!.add("Kampong Chhnang")
provinceList!!.add("Phnom Penh")
provinceList!!.add("Kandal")
provinceList!!.add("Kampot")
spProvince!!.setItem<Any>(provinceList!!)
spProvince!!.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(adapterView: AdapterView<*>, view: View, position: Int, id: Long) {
Toast.makeText(this@MainActivity, provinceList!![position], Toast.LENGTH_SHORT).show()
}
override fun onNothingSelected(adapterView: AdapterView<*>) {}
}
}
}
Each raised issue, should be provided with some information to be easy for me to replicate it like Device Model
, Android version
and log message or file
You can create issue on Github to record issue history then to make it fast alert to me, you can send me email or post to Facebook group for any discussion
If you want to contribute in this library, please fork
this repository and create pull request.