EditText set text start 10dp from left border

后端 未结 4 1730
花落未央
花落未央 2020-12-24 10:36

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

相关标签:
4条回答
  • 2020-12-24 11:07

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

    0 讨论(0)
  • 2020-12-24 11:18

    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"
    />
    
    0 讨论(0)
  • 2020-12-24 11:21

    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.

    0 讨论(0)
  • 2020-12-24 11:24

    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

    0 讨论(0)
提交回复
热议问题