How to align the text to the center of the spinner?
code that I am using:
<Spinner android:id="@+id/s_change_type"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textAlignment="center"
style="@style/Spinner"
android:layout_height="wrap_content"/>
Spinner:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:singleLine="true"
style="?android:attr/spinnerItemStyle"
android:gravity="center"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:textAlignment="inherit"
android:padding="10dp"
android:layout_margin="5dp"
android:layout_height="wrap_content"
android:ellipsize="marquee"/>
Style used by spinner:
<style name="Spinner"
parent="Widget.AppCompat.Spinner.Underlined">
<item name="android:textColor">@color/color_text</item>
<item name="android:textSize">12sp</item>
<item name="android:paddingLeft">@dimen/margin_general_left</item>
<item name="android:paddingRight">@dimen/margin_general_right</item>
</style>
Thanks
One way to center text or put it in the middle of the page is to enclose it within <center></center> tags. Inserting this text within HTML code would yield the following result: Center this text!
To set the heading alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <h1> to <h6> tag, with the CSS property text-align.
In your TextView
write:
android:layout_width="match_parent"
Instead of:
android:layout_width="wrap_content"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With