If you want to learn how to change color of Spinner in Android. I show you all of the steps involved in change #spinner color and spinner dropdown color in #android studio
----------------------------------------------
Subscribe for more Android tips: [ Ссылка ]
Question Of The Day :- Create custom Spinner Android
Share your Solution: Facebook: [ Ссылка ]
Solution: [ Ссылка ]
Share this Question : [ Ссылка ]
----------------------------------------------
Hey guys welcome to #Androchunk. In this video you learn how to change color of spinner in android.
To change the color of spinner you'll need two different layouts
1. CheckedTextView:- use for the selected item of the spinner.
2. TextView:- use for the item of the dropdown list.
and set both layouts to the adapter of the spinner.
Follow these steps to change the color of the spinner.
1. Create a Spinner element in your XML layout.
2. Create a list for the spinner.
3. Create a layout for the selected item of the spinner.
4. Create a layout for the item of the dropdown list.
5. Create the spinner adapter using the Spinner Adapter class and set the CheckedTextView layout as a spinner layout and TextView for the item of the dropdown list.
6. Attach the adapter to Spinner and setOnItemSelectedListener to Spinner.
code snippet for the above steps
Create a Spinner element in your XML layout.:- write the following code in your,XML file.
(Code in the Comment section #1 )
Create ArrayList for the spinner:- you’ll need data to display into the spinner as a dropdown list so for that you’ll need to create ArrayList for the spinner. The following shows a simple array called spinner_items. Copy the following values in the strings.xml file:
(Code in the Comment section #2)
Create a layout for the selected item of the spinner:- create new layout file name color_spinner_layout.xml with CheckedTextView as a root element. Copy the following values in the color_spinner_layout.xml file:
(Code in the Comment section #3)
Create a layout for the item of the dropdown list:- create new layout file name spinner_dropdown_layout.xml with TextView as a root element. Copy the following values in the spinner_dropdown_layout.xml file.
(Code in the Comment section #4)
Create the spinner adapter:- Adapter is used as a bridge in the spinner. It attaches list data into the spinner and creates a dropdown list of that data.do this is when the view is created in the onCreate() method.
we create an adapter from the resource(ArrayList ) which take 3 parameters,
1. context.
2. list: here your list from the string.xml
3. layout for the spinner selected item: your custom layout for spinner selected item.
set spinner_dropdown_layout as a DropDownViewResource for custom drop down items.
(Code in the Comment section #5)
Attach the adapter to Spinner and setOnItemSelectedListener to Spinner:
(Code in the Comment section #6 )
For handle the item selection you’ll need to attach onItemSelectedListener to the spinner and implement it’s two methods.
1. onItemSelected: this method called when item selection is changed.
2. onNothingSelected: this method call when no item is selected for ex: remove the selected item from the list
(Code in the Comment section #7 )
----------------------------------------------
Full source code:- [ Ссылка ]
Learn more about Spinner :- [ Ссылка ]
Subscribe for more Android tutorials: [ Ссылка ]
----------------------------------------------
If you have a topic you want me to make a video about use #Androchunk in the comments.
If you have any questions, comments or suggestions about this video scripts please leave them in the comments.
Official documentation:
Spinner: [ Ссылка ]
SpinnerAdapter: [ Ссылка ]
AdapterView.OnItemSelectedListener: [ Ссылка ]
----------------------------------------------
Music Credits:
Title: Dawn
Artist: Sappheiros
change spinner text color android studio
Теги
SpinnerAndroidAndroid Studioandroid spinnerandroid spinner dropdownandroid spinner adapterandroid dropdownandroid drop downandroid drop down listandroid drop down menuandroid drop down buttonandroid dropdown exampleSpinner viewandroid spinner exampleandroid spinner tutorialspinner in androidspinner text colorspinner textviewspinner onnothingselectedspinner onitemselectedcolor spinner