How do you reduce space between floating editText hint and editText box in Android?

℡╲_俬逩灬. 提交于 2020-01-03 07:19:13

问题


I have an EditText with a floating hint but I was wondering how I would reduce the space between the floating hint and the EditText box.

Right now my UI looks like http://imgur.com/9hQzzx4 and I want to reduce the space between the "Title" floating hint and the EditText box.

Here's the code to my xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp">

        <EditText
            style="@style/Widget.AppCompat.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="40dp"
            android:hint="Title"/>

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp">

        <EditText
            style="@style/Widget.AppCompat.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="32dp"
            android:hint="Details"/>

    </android.support.design.widget.TextInputLayout>

</LinearLayout>

回答1:


Just set paddingTop attribute on EditText element.

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/place_name"
        android:inputType="text"
        android:hint="@string/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="0dp"/>

</android.support.design.widget.TextInputLayout>


来源:https://stackoverflow.com/questions/30946041/how-do-you-reduce-space-between-floating-edittext-hint-and-edittext-box-in-andro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!