As my predecessor pointed out, you cannot do this in the main XML layout file where the Spinner component is located.
And the answer above is good, but if we want to use the best practices of Google, as you know ... use styles for everything ... you could do it with 3 simple steps as follows:
Step 1: You need an additional file in your layout folder with a search for Spinner elements:
<?xml version="1.0" encoding="utf-8"?> <TextView android:id="@+id/textViewSpinnerItem" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/SpinnerTextViewItem" xmlns:android="http://schemas.android.com/apk/res/android" />
Name this file: spinner_item_text.xml
Step 2: Then in the activity class, when you populate Spinner with an array of elements:
adapter = new ArrayAdapter<CharSequence>(this, R.layout.spinner_item_text, items); spinner.setAdapter(adapter);
Note that the R.layout.spinner_item_text resource is in your own R.
Step 3: In the folder with your values, create or use (you already have) the styles.xml file. The required style entry should look like this:
<style name="SpinnerTextViewItem" parent="@android:style/Widget.TextView" > <item name="android:textSize" >8dp</item> <item name="android:textStyle" >bold</item> </style>
What is it!
Until now, it was really very convenient to place all the text sizes, styles, colors, etc. in styles.xml, so itβs easy to maintain.
Oscar S.
source share