2

How I can change the title (color, background, textSize...) of the spinner. I have looked some post, but do not have the same code that my app.

main.class

public class cargarSpinner() {

      listaSpinner = new ArrayList<SpinnerInfo>();  
  listaSpinner = cargarListSpinner();

      SpinnerAdapter myAdapter = new SpinnerAdapter
            (this, 
                    android.R.layout.simple_spinner_item, 
                    listaSpinner);

      spinner.setPrompt("Title");
      spinner.setAdapter(myAdapter);
}

spinner_row.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fondoSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/spinner_naranja_gradiente"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/imageSpinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<TextView
    android:id="@+id/textSpinner"
    style="@style/SpinnerText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"/> 
user3092292
  • 49
  • 2
  • 2
  • 9

4 Answers4

3

in XMl use this :

android:prompt="@string/spinner_title

in java code:

spinner.setPrompt("Title")
Anjali Tripathi
  • 1,477
  • 9
  • 28
  • Go through this link..it may be help u..http://stackoverflow.com/questions/9476665/how-to-change-spinner-text-size-and-text-color – Anjali Tripathi Jan 22 '14 at 11:54
1

You can create custom spinner layout with custom spinner adapter as follow

Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        R.array.travelreasons, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

your layout.simple_spinner_item

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="@style/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />

Your layout.simple_spinner_dropdown_item

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/text1"
style="@style/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/dropdownListPreferredItemHeight"
android:ellipsize="marquee" />

For styles add your custom dimensions and height as per your requirement.

<style name="spinnerItemStyle" parent="android:Widget.TextView.SpinnerItem">

  </style>

  <style name="spinnerDropDownItemStyle" parent="android:TextAppearance.Widget.TextView.SpinnerItem">

  </style>

Source

Community
  • 1
  • 1
dinesh sharma
  • 3,312
  • 1
  • 22
  • 32
0

Try this:

Spannable wordtoSpan = new SpannableString("Title");
    wordtoSpan.setSpan(new ForegroundColorSpan(Color.WHITE), 0,
            wordtoSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    wordtoSpan.setSpan(new BackgroundColorSpan(Color.RED), 0,
            wordtoSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

spinner.setPrompt(wordtoSpan);
user543
  • 3,623
  • 2
  • 16
  • 14
-1

Using Java (Code):

spinner.setPrompt("Title")

OR

From XML:

android:prompt="@string/spinner_title

for styling it

please see this link

Community
  • 1
  • 1
Shruti
  • 1
  • 13
  • 55
  • 95