TextInputLayout:如何给填充或保证金暗示? [英] TextInputLayout :How to give padding or margin to hint?

查看:312
本文介绍了TextInputLayout:如何给填充或保证金暗示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 TextInputLayout 设计支持库。我想给间距提示的EditText TextInputLayout 。我设置margin和padding在 TextInputLayout ,甚至在的EditText 但都没有work.So如何解决这个问题。在这里,我附上截图和我的编码。

I have to use TextInputLayout of design support library in my project. I want to give space between hint and EditText in TextInputLayout. I set margin and padding in TextInputLayout and even inside EditText but both are not work.So how to solve this issue. Here i attach screen shot and my coding.

==============================Style=================================

<style name="TextHint" parent="Base.TextAppearance.AppCompat">
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">@color/green</item>
</style>



=============================XML===================================  
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    app:hintTextAppearance="@style/TextHint"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp"
    android:layout_height="wrap_content">
<EditText
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:id="@+id/edttxtEmailAddress"
    android:singleLine="true"
    android:hint="@string/enter_valid_email"
    android:paddingLeft="20dp"
    android:textSize="20sp"
    android:background="@drawable/rounded_common"/>
</android.support.design.widget.TextInputLayout>

推荐答案

由ganesh2shiv提出的解决方案适用于大多数情况下,虽然我发现它也去中心内的EditText显示的提示文本不集中的时候。

The solution proposed by ganesh2shiv works for the most part, although I've found it also de-centres the hint text displayed inside the EditText when not focused.

一个更好的技巧是所需的 paddingTop 设置为EditText上也嵌入的EditText的背景内的微胖。一个相当明智的办法做到这一点是包装您的原始背景在&LT;层列表&gt; 并设置&LT;项目的android:顶部= ......&GT; 属性相匹配的 paddingTop 您的EditText的

A better trick is to set the desired paddingTop to the EditText but also embed the extra padding within the EditText's background. A fairly sane way to do this is to wrap your original background in a <layer-list> and set the <item android:top="..."> attribute to match the paddingTop of your EditText.

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

  <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/floating_hint_margin"
    android:background="@drawable/bg_edit_text.xml" />
</android.support.design.widget.TextInputLayout>

以及 bg_edit_text.xml 绘文件:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:top="@dimen/floating_hint_margin">
    <your original background; can be <bitmap> or <shape> or whatever./>
  </item>
</layer-list>

这篇关于TextInputLayout:如何给填充或保证金暗示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆