Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the left padding on an Android EditText

Tags:

The default EditText background seems to put ~ 4dp of padding on the left. This causes misalignment with other widgets.

I made a simple app to demonstrate. Screenshot:

Left padding on EditText

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingLeft="@dimen/activity_horizontal_margin"     android:paddingRight="@dimen/activity_horizontal_margin"     android:paddingTop="@dimen/activity_vertical_margin"     android:paddingBottom="@dimen/activity_vertical_margin"     android:orientation="vertical"     tools:context=".MainActivity">       <TextView         android:background="#00ff00"         android:text="@string/hello_world"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/>     <EditText         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:hint="HINT"         android:text="TEXT"         android:singleLine="true"/>     <TextView         android:background="#00ff00"         android:text="@string/hello_world"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/>  </LinearLayout> 

Is there anyway to stop it from doing this?

like image 542
Xiao Avatar asked Jul 30 '15 22:07

Xiao


People also ask

How do I remove Textinputlayout padding?

By default, some space is reserved for assistive labels below SfTextInputLayout control. These reserved spaces can be removed by setting ReserveSpaceForAssistiveLabels property as false when helper and error text are empty and ShowCharCount is false.

What is Android padding in Android Studio?

The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific number of pixels. For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge.

How do I edit EditText Uneditable?

In your xml code set focusable="false" , android:clickable="false" and android:cursorVisible="false" and this will make your EditText treat like non editable.


1 Answers

One workaround is to use negative margin on the sides (-4dp)

This will only work when the EditText background matches the Layout background, and you don't have anything on the sides in the Layout that would be covered by the EditText

like image 62
Peckata Avatar answered Sep 25 '22 04:09

Peckata