Question Detail

this is my code

 

<Spinner
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
 style="@style/SpinnerItemStyle"
    android:layout_marginRight="@dimen/layout_padding_5dp"
    android:entries="@array/currency" />

 

inn style.xml

<style name="SpinnerItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
    <item name="android:textColor">@color/dark_grey_txt_color</item>
    <item name="android:textSize">@dimen/normal_text_size</item>
</style>

 

still isnt working


Thread Reply

viniti vaddepalli

- 1 years ago

I have used this but, if is any modification needed or easy way.

in .java file

public class Personal_Details extends AppCompatActivity {

    Spinner currency;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal__details);



        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        setTitle("Edit Account Details");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        currency= (Spinner) findViewById(R.id.currency);
       currency.setOnItemSelectedListener(spinner_selected);

    }

    private AdapterView.OnItemSelectedListener spinner_selected= new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            ((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
            ((TextView) parent.getChildAt(0)).setTextSize(5);

        }

        public void onNothingSelected(AdapterView<?> parent) {

        }
    };}

 

Hemant Sharma

- 1 years ago

Make a custom XML file for your spinner item.

spinnr_item.xml:

Give your customized color and size to text in this file.

<?xml version="1.0" encoding="utf-8"?>
<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:textSize="20px"
    android:gravity="left"  
    android:textColor="#000"         
    android:padding="5dp"
    />

Now use this file to show your spinner items like:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinnr_item,list);

You don't need to set the drop down resource. It will take spinnr_item.xml only to show your items in spinner.

Bili Greed

- 1 years ago

What you need to do is create your own layout file with a custom definition for the spinner item. This is my spinner_item.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:textColor="#ff0000" />

And then change your declaration of the spinner to use the R.layout.spinner_item:

ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.spinner_item);
spinner.setAdapter(adapter);

Bili Greed

- 1 years ago

include 

<item name="android:spinnerItemStyle">@style/SpinnerItem</item>

in your main style. and make more style


<style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem">
    <item name="android:textColor">#ffffff</item>
    <item name="android:background">#c5000000</item>
    <item name="android:padding">@dimen/textSize</item>
</style>

Surely it will work for you...