EditText set text start 10dp from left border

Android

Android Problem Overview


Is possible in android EditText widget to set that text start 10dp from left border ? When I type something at the moment it is glued to left side and I need to put a little padding.

Android Solutions


Solution 1 - Android

This can be achieved with the android:padding attribute.

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp" />

has a 10dp padding on all sides

you may just want to specify the left and right padding.

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" />

Will make the padding on the left and right be 10dp.

Solution 2 - Android

Use paddingStart (and paddingEnd)

<TextView
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="10pt"
    android:textColor="#646464"
    android:paddingStart="10dp"
    android:paddingEnd="10dp"
    android:maxLines="1"
    android:ellipsize="end"
/>

Solution 3 - Android

Did this really solve your problem? setting padding on xml doesn't seem to apply on EditText for me. I solved it some other way. Placed the EditText in side a RelativeLayout view and applied the padding to that RelativeLayout.

<RelativeLayout
        android:layout_width="258dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:paddingLeft="5dp"
        android:background="@drawable/textbox_bg">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/emailText"
            android:text="text inside"
            android:inputType="textEmailAddress"
            android:background="@android:color/transparent" />
         </RelativeLayout>

as i had issues with EditText background RelativeLayout and set the EditText background transparent. Hope this helps

Solution 4 - Android

I solved using android:layout_marginLeft/android:layout_marginRight. Padding just changed the cursor position.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDamirView Question on Stackoverflow
Solution 1 - AndroidMatthew RudyView Answer on Stackoverflow
Solution 2 - AndroidGary DaviesView Answer on Stackoverflow
Solution 3 - AndroidEarlySunView Answer on Stackoverflow
Solution 4 - AndroidAmandaHLAView Answer on Stackoverflow