Reputation: 1716
I've various layouts in my app, I've added a code to change the language, and by that it change the layout direction and did some steps, using those steps some of my layouts switched to RTL, but I've 2 layouts that still in LTR layout mode .
The Steps i did :
Add support RTL in AndroidManiFest.xml .
Use "start/end" instead of"left/right" .
Change lang Code :
Locale locale = new Locale("ar");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
Screenshot : Here
Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="2.5dp"
android:layout_marginBottom="2.5dp"
card_view:cardUseCompatPadding="true"
android:id="@+id/cardView"
android:foreground="?attr/selectableItemBackground"
android:stateListAnimator="@anim/lift_on_touch">
<RelativeLayout
android:id="@+id/rvs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.pkmmte.view.CircularImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/episode_icon"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_margin="10dp"
app:border_color="#EEEEEE"
app:border_width="0dp"
app:shadow="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="عنوان"
android:id="@+id/episode_title"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/episode_icon"
android:layout_toStartOf="@+id/episode_icon"
android:layout_marginRight="11dp"
android:layout_marginEnd="11dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
Back Arrow & Activity Style :
<style name="Detail" parent="AppTheme">
<item name="toolbarStyle">@style/Widget.Toolbar</item>
</style>
<style name="Widget.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
<item name="navigationIcon">?attr/homeAsUpIndicator</item>
<item name="android:background">?attr/colorPrimary</item>
</style> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
In Android Studio, in RTL view mode, it's correct, but on the real testing, the arrow is in the wrong way, the items are in the wrong way, but the FAB is in the correct way which is weird .
Upvotes: 2
Views: 1617
Reputation: 8714
The layout will be forced to RTL after adding this line: android:layoutDirection="rtl"
to your top level RelativeLayout
Upvotes: 0
Reputation: 11
By "wrong way" did you mean that the layout elements are inverted? If so, there are a few things you can try:
1) When supporting RTL layout stay away form xml attributes containing Left/Right and instead use the ones containng Start/End>
For example: instead of using
android:layout_alignParentRight="true"
try:
android:layout_alignParentEnd="true"
2) Try using linear instead of relative layout. They are easier to manage in RTL cases
Upvotes: 1