Align Text In Center - Spinner
Here is The Code : spinner.xml :
Solution 1:
Use following tag on spinner
android:textAlignment="center"
Solution 2:
Simply add in your default app theme style this two lines :
<item name="android:spinnerItemStyle">@style/spinnerItemStyle</item>
<item name="android:spinnerDropDownItemStyle">
@style/spinnerDropDownItemStyle
</item>
create the new style :
<stylename="spinnerItemStyle"><itemname="android:gravity">center</item></style><stylename="spinnerDropDownItemStyle"><itemname="android:gravity">center</item></style>
Thats it !
Note that the base theme used here is : Theme.AppCompat.Light and this will be applied as the default spinner styles in your app.
Solution 3:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ellipsize="marquee"
android:textAlignment="center"
android:textSize="17sp"
tools:ignore="MissingPrefix" />
Use this Textview as the layout passed to your adapter.
android:textAlignment="center"
this line is the one who makes the magic
Solution 4:
Add this line in your Spinner,
android:textAlignment="center"
Done!
Solution 5:
In your layout add "theme" attribute in Spinner like -
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/_10sdp"
android:theme="@style/CustomSpinnerTheme"
android:entries="@array/entries"
android:gravity="center"
/>
and add style (in values/style file) -
<!-- Spinner style --><stylename="CustomSpinnerTheme"><itemname="android:textSize">@dimen/_15ssp</item><itemname="android:textColor">@color/textMainColor</item><itemname="android:gravity">center</item><itemname="android:textAlignment">center</item></style>
Enjoy :)
Post a Comment for "Align Text In Center - Spinner"