I wasted the last hour trying to figure out how to get rid of this padding in a simple EditText:
All I want is to align the input with the rest of the content, just like the beautiful design guide says.
The layout couldn't be simpler:
<ScrollView 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"
tools:context="com.actinarium.tiomantas.SetupChallengeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/new_challenge_name"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/new_challenge_name_hint1"
android:singleLine="false"/>
</LinearLayout>
</ScrollView>
I tried setting padding on EditText to 0dp — the text shifted but the line remained as is. Strangely enough, I could not find ANY info on this issue, as if no one had noticed.
You can just set the start and end padding on the inner EditText to 0dp. Here's a screenshot with Show Layout Bounds turned on so you can see that the hints go all the way to the edge of the view.
android:drawablePadding is used for space between image and text.
You can use android:includeFontPadding="false" to get rid of the default padding in a TextView . Android docs say this about the attribute: Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly.
A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing.
Indeed EditText has its own drawable padding which remains even after setting all paddings/margins to zero in xml. To fully remove padding from EditText you have to remove it from its drawable which in fact is InsetDrawable.
Android EditText Control Drawable : Android EditText Control is a thin veneer over TextView that configures itself to be editable. Its base class is android.widget.
User can enter text values in Edit text control. You can configure Android EditText control to accept different values.
Add a EditText in activity_main.xml file. Add a Button in activity_main.xml file. Open MainActivity.kt file and set OnClickListner for the button to get the user input from EditText and show the input as Toast message. Used to specify how to align the text like left, right, center, top, etc.
I think the line is a background image for the EditText so changing the padding won't affect it. If you want you can create a custom background drawable that has no padding.
Another hack you could do is add a negative margin to the EditText:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-4dp"
android:hint="@string/new_challenge_name_hint1"
android:singleLine="false"/>
Try giving "4dp" of padding for textView. So that it matches with editText padding.
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