问题
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
回答1:
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...
回答2:
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"
来源:https://stackoverflow.com/questions/53909697/android-spinner-set-dropdown-text-direction-to-rtl