Change Hint Gravity - Edittext

Asked

Viewed 250 times

0

In the xml of my edittext I put the property Gravity to always leave the cursor at the end, however I needed to leave the text hint at the beginning.
It is possible to set a Gravity property for the text and another for the hint?
Follow the xml code of my Edittext:

<EditText
                android:id="@+id/txtHorimetro"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColorHint="#000000"
                android:inputType="numberDecimal"
                android:hint="Horimetro *"
                android:textSize="20sp"
                android:gravity="right"
                android:layout_marginTop="20dp"
                android:layout_below="@+id/txtLitros"
                android:layout_alignStart="@+id/txtLitros"
                android:layout_alignEnd="@+id/txtLitros" />

1 answer

2

Matheus,

For the text, you can use the setSelection, for example:

EditText editText = (EditText)findViewById(R.id.edittext_id);
editText.setSelection(editText.getText().length());

This way Java will check the text that is typed in the field, and will place the cursor after the last character.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.