Android Tutorial RTL Layout Support

1.Declare in your app manifest that your app supports RTL mirroring.
Specifically, add below code in your manifest.
B4X:
SetApplicationAttribute (android:supportsRtl, true)

2. Copy the code you need from below and call it in Activity_Create or any sub you want to use it.

B4X:
Sub ForceRtlSupported4View(View As View)
    Dim jA,jos As JavaObject
    jos.InitializeStatic  ("android.view.View")
    If jA.InitializeStatic  ("android.os.Build$VERSION").GetField ("SDK_INT") > 16 Then
        jA = View
        jA.RunMethod ("setLayoutDirection",Array(jos.GetField ("LAYOUT_DIRECTION_RTL")))
    End If
End Sub

Sub ForceLtrSupported4View(View As View)
    Dim jA,jos As JavaObject
    jos.InitializeStatic  ("android.view.View")
    If jA.InitializeStatic  ("android.os.Build$VERSION").GetField ("SDK_INT") > 16 Then
        jA = View
        jA.RunMethod ("setLayoutDirection",Array(jos.GetField ("LAYOUT_DIRECTION_LTR")))
    End If
End Sub

Sub ForceRtlSupported
    Dim j,jo As JavaObject
    jo.InitializeStatic  ("android.view.View")
    If j.InitializeStatic  ("android.os.Build$VERSION").GetField ("SDK_INT") > 16 Then
        j.InitializeContext.RunMethodJO("getWindow",Null).RunMethodJO("getDecorView",Null) _
.RunMethod ("setLayoutDirection",Array(jo.GetField ("LAYOUT_DIRECTION_RTL")))
    End If
End Sub

Sub ForceLtrSupported
    Dim j,jo As JavaObject
    jo.InitializeStatic  ("android.view.View")
    If j.InitializeStatic  ("android.os.Build$VERSION").GetField ("SDK_INT") > 16 Then
        j.InitializeContext.RunMethodJO("getWindow",Null).RunMethodJO("getDecorView",Null) _
.RunMethod ("setLayoutDirection",Array(jo.GetField ("LAYOUT_DIRECTION_LTR")))
    End If
End Sub

B4X:
 android:minSdkVersion="17"

https://developer.android.com/about/versions/android-4.2#RTL
 
Last edited:

Star-Dust

Expert
Licensed User
It's interesting, but don't you get the same result by rotating on the Y axis in the view rotation functions like in this tutorial?


Here requires no addition on the Manifest
 

mshafiee110

Active Member
Licensed User
It's interesting, but don't you get the same result by rotating on the Y axis in the view rotation functions like in this tutorial?


Here requires no addition on the Manifest

The two methods are different .

Screenshot_1589370725.png
 
Top