Rahul
Rahul

Reputation: 3349

android Material Edittext error appears on left if RTL is implemented

I'm working on application which support multi-language (English and Arabic).

EditText error appears on left side if app language in Arabic. I have tried all the tricks like

gravity=start 
textAlignment=viewStart
layoutDirection=anyRtl 

etc but not working. Please help me :(

Here is the screen shot of issue am facing.

enter image description here

Here is the code

<appname.util.customview.MaterialEditText
        android:id="@+id/met_email_phone"
        style="@style/material_edit_text"
        android:layout_marginEnd="@dimen/margin_large_30"
        android:layout_marginStart="@dimen/margin_large_30"
        android:layout_marginTop="@dimen/margin_xlarge"
        android:backgroundTint="@color/colorAccent"
        android:hint="@string/email_phone"
        android:inputType="textEmailAddress"
        app:met_primaryColor="@color/met_underline" />

And style of edittext is

<style name="material_edit_text">
    <item name="android:gravity">start</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:maxLines">1</item>
    <item name="android:maxLength">30</item>
    <item name="android:textDirection">anyRtl</item>
    <item name="android:textAlignment">viewStart</item>
    <item name="android:layout_marginStart">@dimen/margin_large</item>
    <item name="android:layout_marginEnd">@dimen/margin_large</item>
    <item name="android:textCursorDrawable">@color/tc_header</item>
    <item name="android:layout_marginTop">@dimen/margin_small</item>
</style>

Upvotes: 4

Views: 933

Answers (2)

Dattu Hujare
Dattu Hujare

Reputation: 41

Use below properties in MaterialEditText and remove gravity if any and textAlignment also

 android:layoutDirection="rtl"
 android:textDirection="rtl"

This will be helpful if you are using specific Layout(for eg. layout-ar). Better avoid custom library and Simply use

 android:layoutDirection="locale"
 android:textDirection="locale"

as suggested by Nermeen Saleh

Upvotes: 0

Nermeen Saleh
Nermeen Saleh

Reputation: 132

Set these two properties to locale

 android:layoutDirection="locale"
 android:textDirection="locale"

Upvotes: 1

Related Questions