Hi i have a edit text with the hint, i made the hint as middle using android:gravity:"center"
. when i start typing from in the edittext the typing is starting from the middle, how to make the typing start from leftcorner while still hint is centered
<EditText
android:id="@+id/edittext"
android:layout_width="230dp"
android:layout_height="110dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_marginTop="33dp"
android:layout_toLeftOf="@+id/relativeLayout1"
android:background="@drawable/roundcorners"
android:ems="10"
android:gravity="center_horizontal"
android:hint="@string/fbhint"
android:lines="6"
android:paddingRight="5dp"
android:textSize="14sp"
android:windowSoftInputMode="stateHidden" />
I don't think this is possible "out-of-the box" but you can do it programmatically:
yourEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 0){
// position the text type in the left top corner
yourEditText.setGravity(Gravity.LEFT | Gravity.TOP);
}else{
// no text entered. Center the hint text.
yourEditText.setGravity(Gravity.CENTER);
}
}
}
By default android EditText has center gravity. Just make it android:gravity="top|left"
Also there is no any special attribute for making hint in center and text in top. Both follow the same gravity attribute.
Android hint is a just for something like a label for where user has to start input the characters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With