2016-02-13 16 views
5

Mam problem z kursorem wprowadzania danych Android w językach RTL. Kiedy jestem w układzie wsparcia RTL, mam dwa kursory wejściowe i to naprawdę zabawne. Czy ma prawdziwe rozwiązanie, aby się tego pozbyć?Kursor Android w językach RTL

używam tego kodu, aby mój android UI RTL:

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL); 

A to mój xml dla widoku tekstowego:

<android.support.design.widget.TextInputLayout 
     android:id="@+id/input_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="numberDecimal" 
      android:id="@+id/myID" 
      android:maxLines="1" 
      android:focusableInTouchMode="true" 
      android:layout_weight="0.25" 
      android:layout_gravity="center_horizontal" 
      android:hint="phone Number" 
      android:maxLength="20" 
      android:gravity="center" /> 
    </android.support.design.widget.TextInputLayout> 

enter image description here

+0

Mogę być z powodu, że ustawiłeś grawitację edittext na środek i kursor się pomylił. To nie powinno się zdarzyć, ale spróbuj lewą prawą grawitację, wtedy może nie być problemu. lepiej dać początek wartości grawitacji –

+0

@CreativeAndroid Zrobiłem wszystko, co powiedziałeś i nadal ten sam problem. –

+0

dodaj swój edittext xml –

Odpowiedz

1

rozwiązać ten problem. Po prostu ustaw tekst w tekście od lewej do prawej, a problem zostanie rozwiązany.

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/PhoneNoET" 
    android:layout_marginTop="64dp" 
    android:layout_below="@+id/textView6" 
    android:layout_centerHorizontal="true" 
    android:textAlignment="center" 
    android:maxLength="11" 
    android:layoutDirection="ltr"/> 

Dodaj powyższy layoutDirection do edytowanego tekstu i napraw problem.

0

postanowiłem je za pomocą poniższego ..

W układzie xml, do pola tekstowego edycji dodać this ->

android:textDirection="anyRtl" 

Tutaj "EditText" jest Pana pogląd pola edycji tekstu. tj.

EditText editText = (EditText) findViewById(R.id.edit_text); 

Następnie programowo dodaj obserwator tekstu dla tego edytowanego tekstu.

editText.addTextChangedListener(new TextWatcher() { 
       @Override 
       public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

       } 

       @Override 
       public void onTextChanged(CharSequence s, int start, int before, int count) { 
        editText.setSelection(s.length()); // this line is very important for setting cursor position 
       } 

       @Override 
       public void afterTextChanged(Editable s) { 

       } 
      }); 
     } 

To zadziałało dla mnie!

Powiązane problemy