Android Spinner Set dropdown text direction to RTL
Asked Answered
I

3

5

How to set spinner dropdown text direction to rtl? I know for regular texts we can use android:textDirection="rtl" but it does not work for spinner dropdown text. Should I implement it in popup theme? How?

Thanks

Impatiens answered 24/12, 2018 at 5:58 Comment(0)
T
6

This will fix the issue.. enjoy

android:textAlignment="viewStart"
Trierarch answered 21/2, 2020 at 13:27 Comment(0)
B
3

Try This -

Add below code in Activity

Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, 
R.array.planets_array,
//        android.R.layout.simple_spinner_item);
    R.layout.textview);
//    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(R.layout.textview);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

textview.xml

<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" />

Change Gravity as per your requirement... Hope this will help...

Blameworthy answered 24/12, 2018 at 6:35 Comment(0)
S
3

First of all make sure that you enabled rtl support in AndroidManifest.xml

    <application
    ...
    android:supportsRtl="true"
    ...>

after that use this in your Spinner definition :

android:layoutDirection="rtl"
android:textDirection="rtl"
Shavonneshaw answered 9/11, 2019 at 21:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.