Tags down


How to generate a spinner in Android with different background color in each item with Java?

By : PrintWest
Date : September 17 2020, 02:00 AM
this will help Instead of TextView set BackgroundColor to view. Beside this If you want to colorize the selected view, then you also have to override getView. Check below:
code :
public View getView(int position, View convertView, ViewGroup parent) {
    return getCustomView(position, convertView, parent);

public View getDropDownView(int position, View convertView, ViewGroup parent) {
    return getCustomView(position, convertView, parent);

private View getCustomView(int position, View convertView, ViewGroup parent) {
    View view = super.getDropDownView(position, convertView, parent);

    if (position % 2 == 1) {
    else {

    return view;

Share : facebook icon twitter icon

Android Spinner created dynamically change selected item background color

By : Matthias Güttler
Date : March 29 2020, 07:55 AM
To fix the issue you can do After long time searching for a solution,
I found out that I can't set style or change its selection color dynamically 'cause of the API version that I'm developing.

Android Java Spinner Item Background Color

By : user7892694
Date : March 29 2020, 07:55 AM
This might help you The adapter from Customizing spinner's item background color is precisely what you need. Of course, you need to implement a method returning the desired color for each item of the array.
If your input is the color name (i.e., this spinner acts a color picker, you could use Color.parseColor(). It supports some named colors, plus numeric values.

Change background color of the selected item in Android Spinner

By : Rajdev Singh
Date : March 29 2020, 07:55 AM
Hope that helps You need to implement below method in your adapter class:
It will help you:
code :
 int selectedItem = -1;

 ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list) {

   public View getDropDownView(int position, View convertView, ViewGroup parent)
       View v = null;
       v = super.getDropDownView(position, null, parent);
       // If this is the selected item position
       if (position == selectedItem) {
       else {
           // for other views

       return v;

   selectedItem = position;

Android Java - Dropdown spinner sets the same text always, only want to change background color

By : Arshui
Date : March 29 2020, 07:55 AM
I hope this helps . I have 2 dropdown spinners that I would like to be color coded. I would like 1 to always be labeled as Apple and the other to be Banana. I'm using the dropdown menu to change the background color of the spinner. How do I set the text to always stay as Apple and Banana, but only have the background color of the spinner change based on what is selected? Whenever I use the dropdown to select a color, it changes the text to the color I selected. I feel like I would need a setText function somewhere... , Add below code,
code :
dropdown1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            text1 = dropdown1.getSelectedItem().toString();

            if (text1.equals("red")) {
            } else if (text1.equals("green")) {
            } else if (text1.equals("blue")) {

        public void onNothingSelected(AdapterView<?> parentView) {



Customizing spinner's item background color

By : Melanie Alice
Date : March 29 2020, 07:55 AM
To fix this issue You need to use a custom adapter. I guess you are using an ArrayAdapter? If so you could do it like so:
Related Posts Related Posts :
  • best way to Iterate over a collection and array consecutively
  • How to make Java process to use multiple CPU cores
  • JavaFX 13 create runnable jar "no main manifest attribute"
  • run Java Servlet unit tests on Tomcat server
  • Convert if else statement in Optional.ofNullable().ifPresent() in Java
  • The type com.google.cloud.ServiceOptions$Builder cannot be resolved. It is indirectly referenced from required .class fi
  • Cannot read Excel file with Arabic content using Java
  • Java 13 Text Block *WITHOUT* newlines
  • Time complexity of an algorithm depends on the incremental/decremental step portion, and not the actual input size?
  • java.sql.Connection createArrayOf() returns Unsupported feature
  • Does a Kafka Consumer default batch size?
  • Java runtime memory model --
  • Built-in exception length shorter than expected?
  • code tuning for nested loops for better performance
  • Generate POJO from JSON-LD or RDF to be used with Jackson or GSON
  • How I will display latest image to ImageView Another Activity?
  • Method reference and Generics in Java-8
  • Gradle task assembleDebug failed with exit code 1 (Runtime Exception)
  • How to Import MQTT Paho into Java 'playground'?
  • (Java) Cannot Find Symbol for method
  • Map of generics: read and write
  • Java 11 - Annotation SPI from META-INF/services aren't getting acknowledged
  • Android - Changing app language for all versions of Android
  • bounded type with static method returning String
  • Flutter WebView Crashes on html select
  • Java - cannot convert double to integer while dividing doubles
  • Is there a difference between finding by primary key vs finding by unique column?
  • How to make AnchorPane rounded inside another AnchorPane
  • How do I query Firestore Array Value?
  • Custom Comparator not sorting time
  • java regex to capture any number of periods within a string
  • Spring Singleton means no data sharing at class level?
  • Trying to merge pdfs using iText7 merger, but when I open final merged pdf it says failed to load pdf document
  • Int number = (int)Math.random();
  • Quarkus and Keycloak/OIDC - NullPointerException
  • how to set one value for all elements of data structure in one action(simultaneously)
  • I would like to know how to write Java bytecode that initializes static class variables
  • How do I create a unbalanced binary search tree
  • Why the non-final instance variable of the outer class can be accessed and updated in the anonymous inner class?
  • Writing to a file code causing an endless loop
  • Why I can't show my list from another method?
  • Write in JSON File in a specific position in JAVA
  • From where to load application content
  • Why this nullpointerexception keeps on coming? I have written the error in the end. I have also mentioned the line where
  • ActionListener executes twice on JPanel when called from JFrame
  • How to read PDF from the .jar file
  • Monotonic Functions in Java of Comparables
  • How to fix OOM exception for my apache ignite 2.7.0?
  • How to Parse JSON object partially to Java object
  • Please specify the reason for the given output in following java code
  • How to create fat jar with all dependencies for spring application
  • java.util.Date object created having incorrect time
  • Recommended way to pass configuration to a Kafka client
  • Why does using Unicode in a properties file work but not the actual character even when file.encoding is set?
  • Sending dto with html file in Spring mvc
  • Condition to check if element is present in DOM
  • Serializable Class Containing Sensitive Data
  • How to find the subsequence of number in java in simplest way
  • How to add inner elements from stream to stream?
  • NativeLongByReference contains only 32-bit number on x64 OS
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk