1

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.

Community
  • 1
  • 1
ljbade
  • 4,576
  • 4
  • 30
  • 35

2 Answers2

1

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....

Abhinav Puri
  • 4,254
  • 1
  • 16
  • 28
0

The accepted answer is wrong. Because ?attr/actionBarSize is 56dp!! Its HUGE for text. The right way to do it is set a style to the TextView as follows:

style="@style/ActionBarTitle"

If you are using AppCompat, you can also use this instead:

style="@style/Base.TextAppearance.Widget.AppCompat.Toolbar.Title"

Both achieve the same result. Styles in Android are repeated if you use support libraries.

Ali Kazi
  • 1,561
  • 1
  • 15
  • 22