ljbade ljbade - 4 months ago 63
Android Question

How to set correct text size for a Spinner in an Android Toolbar action bar

I followed these instructions to add a spinner to my Toolbar which I am using as the action bar in my Android app.

However the text size is too small.

How do I get the correct text size for an action bar item?

For an example of the correct size see the Action Bar guide.

Answer

Try adding the below property to your spinner item, it worked for me :

android:textSize="?attr/actionBarSize"

Hope this helps..

Edit :

Okay, I wasn't telling you about toolbar, let me show an example which might help you :

I assumed in my answer that you have a custom layout defined for spinner, if not then have a look at below code :

Define spinnerLayout.xml file in your layout resource :

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/spinnerLayoutItems"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textSize="?attr/actionBarSize"         
          android:textColor="#FF0000"
          android:gravity="center"/>

Now, add this in your activity :

.....
Spinner spinner = (Spinner) findViewById(R.id.spinner);   // Your spinner id in layout.
.....
ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(this,
                                                     R.array.list,R.layout.spinnerLayoutItems);

spinner.setAdapter(adapter);
....

So, I was telling to set your textSize in spinner to "?attr/actionBarSize", you can set it anything, as big as you want.

I am sorry, I by mistake wrote in my previous answer : android:layout_height property, I have corrected it.

Hope this helps....