I'm new to android development and I need proper instructions to right-align activity titles in a min-sdk:8 android application. I can do so by enabling rtl support for my app, but that only takes effect when the user has chosen an rtl language on his/her device. is there a way to force rtl even when the device language is ltr? or any other instructions to right-align titles in ltr mode? thx.
Asked
Active
Viewed 639 times
1
-
Possible duplicate of [Android toolbar center title and custom font](http://stackoverflow.com/questions/26533510/android-toolbar-center-title-and-custom-font) – David Medenjak Jan 17 '16 at 18:42
-
1And **why** would you like to force your LTR users to have their contents aligned such as in RTL languages? This would upset them. – Phantômaxx Jan 17 '16 at 18:52
-
@Hrundi V. Bakshi: because all of my audience are rtl language people but a lot of them leave their os language settings on default ltr (English), so if i design the whole app based on rtl (which will solve my own problem), the other group will see the app mirrored. won't they? but if i can force all people to see the app in rtl then I could rely on a united design. is there a chance to have different layouts for each of rtl and ltr languages in a single app? – mdehghani Jan 17 '16 at 23:08
-
No, they won't see the writings mirrored. They will see the writings just fine (in English): LTR, as they expect from an OS set in English. If the will set the OS (just to say) to Arabian, they will see the tetext in RTL, if so you set the layout for Arabian. – Phantômaxx Jan 17 '16 at 23:15
2 Answers
0
You can set a custom view in your Toolbar
like this:
(copied from How to align center the title or label in activity?)
TextView customView = (TextView)
LayoutInflater.from(this).inflate(R.layout.actionbar_custom_title_view_centered,
null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT, Gravity.RIGHT );
customView.setText("Some centered text");
getSupportActionBar().setCustomView(customView, params);

Community
- 1
- 1

TheoKanning
- 1,631
- 11
- 20
-
somebody has commented over there that: "This only works for API 11+." – mdehghani Jan 18 '16 at 21:27
-
True, but worldwide only about 5% of devices still use Gingerbread or lower, so this could be an acceptable concession depending on your target audience – TheoKanning Jan 19 '16 at 15:47
0
You can do that^. If you were do that multiple times in your app, you can create a customToolbar class that extends Toolbar and overwrite this method and add all that code there^ (and use that custom toolbar in your xml as well)
https://developer.android.com/reference/android/widget/Toolbar.html#generateLayoutParams(android.util.AttributeSet)

Vadim Kotov
- 8,084
- 8
- 48
- 62

inder_gt
- 492
- 1
- 7
- 9