Android: Center Text Inside Edittext Programmatically
Is there any way to center the inputted text in an EditText field? More specifically, instead of the cursor starting at the left of the box, it should start in the center and move
Solution 1:
you should use
textView.setGravity(Gravity.CENTER_HORIZONTAL);
Solution 2:
Try android:gravity="center_horizontal"
in the widget definition in your layout file. This will not strictly "move outward towards the left" -- it should move outward in both directions evenly. If you truly mean you want the text to only be on the left side of the EditText
, I doubt that will be possible.
Solution 3:
Simpler Solution to align text in EditText is to add android:gravity="center" in layout xml. There is no need to add Java code.
Tested Sample Code-
<EditText
android:id="@+id/FieldName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/back"
android:inputType="numberDecimal"
android:gravity="center" />
Post a Comment for "Android: Center Text Inside Edittext Programmatically"