TextInputLayout :How to give padding or margin to hint?











up vote
41
down vote

favorite
9












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>


enter image description here










share|improve this question




















  • 1




    why did you put the edit text in the android.support.design.widget.TextInputLayout
    – Coas Mckey
    Sep 16 '15 at 13:21










  • I guess he wanted to display a hint. But... doesn't the hint xml tag work?
    – Mauker
    Sep 16 '15 at 13:22










  • Because i want to use Floating hint for that EditText.
    – Pranav
    Sep 16 '15 at 13:22










  • @Mauker no hint tag work as you see in image hint display but its overlapping EditText border..so Is there any way to give vertical distance between Hint and EditText?
    – Pranav
    Sep 16 '15 at 13:25












  • @parnav please read my updated answer it contains how to show the erro which you may wana need too as in the case of in correct things etc
    – Coas Mckey
    Sep 16 '15 at 13:32















up vote
41
down vote

favorite
9












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>


enter image description here










share|improve this question




















  • 1




    why did you put the edit text in the android.support.design.widget.TextInputLayout
    – Coas Mckey
    Sep 16 '15 at 13:21










  • I guess he wanted to display a hint. But... doesn't the hint xml tag work?
    – Mauker
    Sep 16 '15 at 13:22










  • Because i want to use Floating hint for that EditText.
    – Pranav
    Sep 16 '15 at 13:22










  • @Mauker no hint tag work as you see in image hint display but its overlapping EditText border..so Is there any way to give vertical distance between Hint and EditText?
    – Pranav
    Sep 16 '15 at 13:25












  • @parnav please read my updated answer it contains how to show the erro which you may wana need too as in the case of in correct things etc
    – Coas Mckey
    Sep 16 '15 at 13:32













up vote
41
down vote

favorite
9









up vote
41
down vote

favorite
9






9





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>


enter image description here










share|improve this question















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>


enter image description here







android android-layout androiddesignsupport android-textinputlayout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 17 '15 at 11:05

























asked Sep 16 '15 at 13:16









Pranav

2,14412126




2,14412126








  • 1




    why did you put the edit text in the android.support.design.widget.TextInputLayout
    – Coas Mckey
    Sep 16 '15 at 13:21










  • I guess he wanted to display a hint. But... doesn't the hint xml tag work?
    – Mauker
    Sep 16 '15 at 13:22










  • Because i want to use Floating hint for that EditText.
    – Pranav
    Sep 16 '15 at 13:22










  • @Mauker no hint tag work as you see in image hint display but its overlapping EditText border..so Is there any way to give vertical distance between Hint and EditText?
    – Pranav
    Sep 16 '15 at 13:25












  • @parnav please read my updated answer it contains how to show the erro which you may wana need too as in the case of in correct things etc
    – Coas Mckey
    Sep 16 '15 at 13:32














  • 1




    why did you put the edit text in the android.support.design.widget.TextInputLayout
    – Coas Mckey
    Sep 16 '15 at 13:21










  • I guess he wanted to display a hint. But... doesn't the hint xml tag work?
    – Mauker
    Sep 16 '15 at 13:22










  • Because i want to use Floating hint for that EditText.
    – Pranav
    Sep 16 '15 at 13:22










  • @Mauker no hint tag work as you see in image hint display but its overlapping EditText border..so Is there any way to give vertical distance between Hint and EditText?
    – Pranav
    Sep 16 '15 at 13:25












  • @parnav please read my updated answer it contains how to show the erro which you may wana need too as in the case of in correct things etc
    – Coas Mckey
    Sep 16 '15 at 13:32








1




1




why did you put the edit text in the android.support.design.widget.TextInputLayout
– Coas Mckey
Sep 16 '15 at 13:21




why did you put the edit text in the android.support.design.widget.TextInputLayout
– Coas Mckey
Sep 16 '15 at 13:21












I guess he wanted to display a hint. But... doesn't the hint xml tag work?
– Mauker
Sep 16 '15 at 13:22




I guess he wanted to display a hint. But... doesn't the hint xml tag work?
– Mauker
Sep 16 '15 at 13:22












Because i want to use Floating hint for that EditText.
– Pranav
Sep 16 '15 at 13:22




Because i want to use Floating hint for that EditText.
– Pranav
Sep 16 '15 at 13:22












@Mauker no hint tag work as you see in image hint display but its overlapping EditText border..so Is there any way to give vertical distance between Hint and EditText?
– Pranav
Sep 16 '15 at 13:25






@Mauker no hint tag work as you see in image hint display but its overlapping EditText border..so Is there any way to give vertical distance between Hint and EditText?
– Pranav
Sep 16 '15 at 13:25














@parnav please read my updated answer it contains how to show the erro which you may wana need too as in the case of in correct things etc
– Coas Mckey
Sep 16 '15 at 13:32




@parnav please read my updated answer it contains how to show the erro which you may wana need too as in the case of in correct things etc
– Coas Mckey
Sep 16 '15 at 13:32












11 Answers
11






active

oldest

votes

















up vote
93
down vote



accepted










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.



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" />
</android.support.design.widget.TextInputLayout>


And the bg_edit_text.xml drawable file:



<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>





share|improve this answer



















  • 1




    this should be the correct answer. @ganesh2shiv answer can cut the edittext background
    – Bronx
    Nov 13 '15 at 14:55










  • this is perfect!
    – Gujarat Santana
    Nov 26 '15 at 23:20






  • 1




    My bad. Thanks for pointing it out. Upvoted. ;)
    – Ganesh Mohan
    Dec 7 '15 at 12:11










  • When we add android:top we are creating an top insert which is space between the border line at the top and edittext top side. so border will be below edit text top side. that why we are using android:paddingTop to compensate for the donated space. This answer locks!
    – Edijae Crusar
    Apr 11 '16 at 14:04






  • 1




    For people who may have an error : remove .xml from the background identifier
    – StevenTB
    May 25 '16 at 9:49


















up vote
22
down vote













I have been looking for the solution to this question from last couple of days myself. After tearing my hairs out for hours I have finally found a simple workaround. What I have noticed is that if you have custom background set on EditText the android:paddingTop attribute simple doesn't work to alter the spacing b/w the hint text and edit text (I have really no idea why). So if you have set custom background to your EditText, you can use android:translationY attribute in the EditText.



So here's your solution:



<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
app:hintTextAppearance="@style/TextHint">

<EditText
android:id="@+id/edttxtEmailAddress"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/rounded_common"
android:hint="@string/enter_valid_email"
android:paddingLeft="20dp"

android:translationY="10dp"

android:singleLine="true"
android:textSize="20sp" />
</android.support.design.widget.TextInputLayout>


Hope it helps. :)





Update: My sincerest apologies for the late update. I have been really busy lately. If you haven't realized yet let me tell you this answer is straight out ugly and wrong. In retrospect I think I was probably drunk when I wrote it. As mentioned by others it might cut the bottom region of the editText background but there's an ugly fix for it as well - you can set the height of the (parent) textInputLayout sightly bigger (how big? you are supposed to find it by trial and error, yuck!) than the (child) editText. I hope you all do realize that would be crazy so please don't do it. Check out the answer written by @Radu Topor, it's by far the best and clean solution to this question. Thanks.






share|improve this answer























  • Great its working thx dude...
    – Pranav
    Sep 28 '15 at 14:27










  • saved my life :) Thanks man!
    – Muhammad Riyaz
    Mar 15 '16 at 11:17










  • Thank you very much!
    – DmitryKanunnikoff
    May 16 '17 at 21:46










  • well its affecting the background layout set in edittext
    – Vicky
    Jul 31 '17 at 8:40










  • thanks. It worked for me.
    – Däñish Shärmà
    Apr 27 at 14:40


















up vote
11
down vote













I tried the padding changes, but it doesn't work well.



A simple workaround is to change the height of the TIL:



android:layout_height="wrap_content"


to (e.g.)



android:layout_height="50dp"


it might not give the same result on all screen sizes.



And add



android:gravity="bottom" 


to push your text down.






share|improve this answer























  • this is simplest solution
    – amorenew
    May 10 at 5:14


















up vote
7
down vote













@RaduTopor 's answer is good, but I think we also need add android:bottom or else it also de-centres the hint text displayed inside the EditText when not focused



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


Before(RaduTopor answer):



not centered



After:



centered






share|improve this answer





















  • Thanks this might be the best solution for that
    – Shhhhhhh
    Jul 5 at 5:12


















up vote
2
down vote













I made a special class for the purpose of adding empty view above EditText, thus add padding to hint. You can use it as simple TextInputLayout.



public class PaddingTextInputLayout extends TextInputLayout {

public View paddingView;

public PaddingTextInputLayout(Context context) {
super(context);
}

public PaddingTextInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public PaddingTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
super.addView(child, index, params);
refreshPaddingView();
}

public void addPaddingView(){
paddingView = new View(getContext());
int height = (int) getContext().getResources()
.getDimension(R.dimen.edittext_text_input_layout_padding);
ViewGroup.LayoutParams paddingParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
height);
super.addView(paddingView, 0, paddingParams);
}

public void refreshPaddingView(){
if (paddingView != null) {
removeView(paddingView);
paddingView = null;
}
addPaddingView();
}
}


This implementation is very simple and stupid, you can improve it a lot.






share|improve this answer




























    up vote
    2
    down vote













    To disable the bottom line cut effect i have used margins, translationY and clipChildren="false"



    <android.support.design.widget.TextInputLayout
    android:id="@+id/textinput"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="8dp"
    android:clipChildren="false">

    <android.support.design.widget.TextInputEditText
    android:id="@+id/et_profile_contact_name"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="3dp"
    android:background="@drawable/image_back"
    android:hint="Contact name"
    android:padding="5dp"
    android:translationY="3dp" />
    </android.support.design.widget.TextInputLayout>





    share|improve this answer




























      up vote
      1
      down vote













      Just add to your EditText custom background



      <?xml version="1.0" encoding="utf-8"?>
      <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
      <shape android:shape="rectangle">
      <padding
      android:top="4dp"/> // your padding value
      </shape>
      </item>
      // customize your background items if you need
      </layer-list>
      <android.support.design.widget.TextInputLayout
      ...>
      <android.support.design.widget.TextInputEditText
      ...
      android:background="@style/your_custom_background"/>


      then apply it to your EditText and increase height of your EditText with your padding value if you use fix height






      share|improve this answer




























        up vote
        0
        down vote













        If the requirement is to add space between cursor and hint then you can try



        editTextComment.setHint("  "+getString(R.string.add_a_comment));





        share|improve this answer




























          up vote
          0
          down vote













          This is what i did in my project for getting enough space between edittext and hint



          <android.support.design.widget.TextInputLayout
          android:id="@+id/til_full_name"
          android:layout_width="match_parent"
          android:layout_height="60dp"
          android:layout_marginStart="40dp"
          android:layout_marginEnd="40dp"
          android:layout_marginTop="30dp"
          android:gravity="bottom"
          android:textColorHint="#fff"
          app:layout_constraintTop_toBottomOf="@+id/welcome_til_email">

          <android.support.v7.widget.AppCompatEditText
          android:id="@+id/et_name"
          android:layout_width="match_parent"
          android:layout_height="40dp"
          android:background="#9a050505"
          android:hint="You email"
          android:inputType="textCapWords"
          android:paddingLeft="10dp"
          android:paddingRight="10dp"
          android:singleLine="true"
          android:textAppearance="?android:textAppearanceSmall"
          android:textColor="#fff"
          app:layout_constraintLeft_toLeftOf="parent"
          app:layout_constraintRight_toRightOf="parent" />
          </android.support.design.widget.TextInputLayout>





          share|improve this answer




























            up vote
            0
            down vote













            This a late answer but hope it helps, And I thinks its a bit better solution. Rather then giving background to your editText , Give that background to your TextInputLayout . And set edittext layout to transparent.



            <android.support.design.widget.TextInputLayout
            android:id="@+id/tinput_phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="05dp"
            android:background="@drawable/send_email_screen_element_bg"
            android:padding="05dp"
            android:theme="@style/grey_control_style">

            <android.support.v7.widget.AppCompatEditText
            android:id="@+id/edt_phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:ems="10"
            android:hint="@string/phone_hint_str"
            android:inputType="text"
            android:paddingStart="10dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:singleLine="true"
            android:textColor="@color/black"
            android:textSize="14sp" />
            </android.support.design.widget.TextInputLayout>





            share|improve this answer




























              up vote
              -1
              down vote













              I think you should consider this:



              The design library takes an interesting approach to customizing the EditText: it doesn’t change it directly. Instead, the TextInputLayout is used to wrap the EditText and provide the enhancements.



              The first one, displaying a floating label when the user types something into the field, is done automagically. The TextInputLayout finds the EditText among its children and attaches itself as a TextWatcher, so it’s able to determine when the field has been modified and animates the movement of the hint from its regular place in the EditText to the floating label position above it.



              The second enhancement, displaying the error message, requires a slight change in code. Instead of setting the error on the EditText, the error should be set on the TextInputLayout. That’s because there is no automatic way for the TextInputLayout to be notified when the error is set on the EditText.
              Here’s what the layout might look like:



              <android.support.design.widget.TextInputLayout
              android:id="@+id/username_text_input_layout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
              <EditText
              android:id="@+id/username_edit_text"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="@string/username_hint"/>
              </android.support.design.widget.TextInputLayout>


              Note that both the EditText and TextInputLayout need layout IDs. In the fragment, we would need to configure the TextInputLayout to enable displaying errors:



              TextInputLayout usernameTextInputLayout = (TextInputLayout) view.findViewById(R.id.username_text_input_layout);
              usernameTextInputLayout.setErrorEnabled(true);
              ...
              usernameTextInputLayout.setError(R.string.username_required);





              share|improve this answer























              • let the hint appear in the Edit text
                – Coas Mckey
                Sep 16 '15 at 13:29










              • No that not what i want,I use background to edit text its expand edittext border beyond its default limit so that hint overlapping the edittext. Is there any method or xml tag that can make margin between Hint and Edittext upper border?
                – Pranav
                Sep 16 '15 at 13:33










              • android:paddingTop="20dp" or what ever suit you
                – Coas Mckey
                Sep 16 '15 at 13:37










              • and remove this tag android:layout_marginTop="10dp" in your TextinputLayout
                – Coas Mckey
                Sep 16 '15 at 13:38












              • please mark this as answer if this helps you
                – Coas Mckey
                Sep 16 '15 at 13:39











              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32609710%2ftextinputlayout-how-to-give-padding-or-margin-to-hint%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              11 Answers
              11






              active

              oldest

              votes








              11 Answers
              11






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              93
              down vote



              accepted










              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.



              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" />
              </android.support.design.widget.TextInputLayout>


              And the bg_edit_text.xml drawable file:



              <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>





              share|improve this answer



















              • 1




                this should be the correct answer. @ganesh2shiv answer can cut the edittext background
                – Bronx
                Nov 13 '15 at 14:55










              • this is perfect!
                – Gujarat Santana
                Nov 26 '15 at 23:20






              • 1




                My bad. Thanks for pointing it out. Upvoted. ;)
                – Ganesh Mohan
                Dec 7 '15 at 12:11










              • When we add android:top we are creating an top insert which is space between the border line at the top and edittext top side. so border will be below edit text top side. that why we are using android:paddingTop to compensate for the donated space. This answer locks!
                – Edijae Crusar
                Apr 11 '16 at 14:04






              • 1




                For people who may have an error : remove .xml from the background identifier
                – StevenTB
                May 25 '16 at 9:49















              up vote
              93
              down vote



              accepted










              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.



              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" />
              </android.support.design.widget.TextInputLayout>


              And the bg_edit_text.xml drawable file:



              <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>





              share|improve this answer



















              • 1




                this should be the correct answer. @ganesh2shiv answer can cut the edittext background
                – Bronx
                Nov 13 '15 at 14:55










              • this is perfect!
                – Gujarat Santana
                Nov 26 '15 at 23:20






              • 1




                My bad. Thanks for pointing it out. Upvoted. ;)
                – Ganesh Mohan
                Dec 7 '15 at 12:11










              • When we add android:top we are creating an top insert which is space between the border line at the top and edittext top side. so border will be below edit text top side. that why we are using android:paddingTop to compensate for the donated space. This answer locks!
                – Edijae Crusar
                Apr 11 '16 at 14:04






              • 1




                For people who may have an error : remove .xml from the background identifier
                – StevenTB
                May 25 '16 at 9:49













              up vote
              93
              down vote



              accepted







              up vote
              93
              down vote



              accepted






              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.



              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" />
              </android.support.design.widget.TextInputLayout>


              And the bg_edit_text.xml drawable file:



              <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>





              share|improve this answer














              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.



              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" />
              </android.support.design.widget.TextInputLayout>


              And the bg_edit_text.xml drawable file:



              <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>






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 25 '16 at 14:36

























              answered Oct 30 '15 at 12:27









              Radu Topor

              99169




              99169








              • 1




                this should be the correct answer. @ganesh2shiv answer can cut the edittext background
                – Bronx
                Nov 13 '15 at 14:55










              • this is perfect!
                – Gujarat Santana
                Nov 26 '15 at 23:20






              • 1




                My bad. Thanks for pointing it out. Upvoted. ;)
                – Ganesh Mohan
                Dec 7 '15 at 12:11










              • When we add android:top we are creating an top insert which is space between the border line at the top and edittext top side. so border will be below edit text top side. that why we are using android:paddingTop to compensate for the donated space. This answer locks!
                – Edijae Crusar
                Apr 11 '16 at 14:04






              • 1




                For people who may have an error : remove .xml from the background identifier
                – StevenTB
                May 25 '16 at 9:49














              • 1




                this should be the correct answer. @ganesh2shiv answer can cut the edittext background
                – Bronx
                Nov 13 '15 at 14:55










              • this is perfect!
                – Gujarat Santana
                Nov 26 '15 at 23:20






              • 1




                My bad. Thanks for pointing it out. Upvoted. ;)
                – Ganesh Mohan
                Dec 7 '15 at 12:11










              • When we add android:top we are creating an top insert which is space between the border line at the top and edittext top side. so border will be below edit text top side. that why we are using android:paddingTop to compensate for the donated space. This answer locks!
                – Edijae Crusar
                Apr 11 '16 at 14:04






              • 1




                For people who may have an error : remove .xml from the background identifier
                – StevenTB
                May 25 '16 at 9:49








              1




              1




              this should be the correct answer. @ganesh2shiv answer can cut the edittext background
              – Bronx
              Nov 13 '15 at 14:55




              this should be the correct answer. @ganesh2shiv answer can cut the edittext background
              – Bronx
              Nov 13 '15 at 14:55












              this is perfect!
              – Gujarat Santana
              Nov 26 '15 at 23:20




              this is perfect!
              – Gujarat Santana
              Nov 26 '15 at 23:20




              1




              1




              My bad. Thanks for pointing it out. Upvoted. ;)
              – Ganesh Mohan
              Dec 7 '15 at 12:11




              My bad. Thanks for pointing it out. Upvoted. ;)
              – Ganesh Mohan
              Dec 7 '15 at 12:11












              When we add android:top we are creating an top insert which is space between the border line at the top and edittext top side. so border will be below edit text top side. that why we are using android:paddingTop to compensate for the donated space. This answer locks!
              – Edijae Crusar
              Apr 11 '16 at 14:04




              When we add android:top we are creating an top insert which is space between the border line at the top and edittext top side. so border will be below edit text top side. that why we are using android:paddingTop to compensate for the donated space. This answer locks!
              – Edijae Crusar
              Apr 11 '16 at 14:04




              1




              1




              For people who may have an error : remove .xml from the background identifier
              – StevenTB
              May 25 '16 at 9:49




              For people who may have an error : remove .xml from the background identifier
              – StevenTB
              May 25 '16 at 9:49












              up vote
              22
              down vote













              I have been looking for the solution to this question from last couple of days myself. After tearing my hairs out for hours I have finally found a simple workaround. What I have noticed is that if you have custom background set on EditText the android:paddingTop attribute simple doesn't work to alter the spacing b/w the hint text and edit text (I have really no idea why). So if you have set custom background to your EditText, you can use android:translationY attribute in the EditText.



              So here's your solution:



              <android.support.design.widget.TextInputLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:layout_marginRight="30dp"
              android:layout_marginTop="10dp"
              app:hintTextAppearance="@style/TextHint">

              <EditText
              android:id="@+id/edttxtEmailAddress"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:background="@drawable/rounded_common"
              android:hint="@string/enter_valid_email"
              android:paddingLeft="20dp"

              android:translationY="10dp"

              android:singleLine="true"
              android:textSize="20sp" />
              </android.support.design.widget.TextInputLayout>


              Hope it helps. :)





              Update: My sincerest apologies for the late update. I have been really busy lately. If you haven't realized yet let me tell you this answer is straight out ugly and wrong. In retrospect I think I was probably drunk when I wrote it. As mentioned by others it might cut the bottom region of the editText background but there's an ugly fix for it as well - you can set the height of the (parent) textInputLayout sightly bigger (how big? you are supposed to find it by trial and error, yuck!) than the (child) editText. I hope you all do realize that would be crazy so please don't do it. Check out the answer written by @Radu Topor, it's by far the best and clean solution to this question. Thanks.






              share|improve this answer























              • Great its working thx dude...
                – Pranav
                Sep 28 '15 at 14:27










              • saved my life :) Thanks man!
                – Muhammad Riyaz
                Mar 15 '16 at 11:17










              • Thank you very much!
                – DmitryKanunnikoff
                May 16 '17 at 21:46










              • well its affecting the background layout set in edittext
                – Vicky
                Jul 31 '17 at 8:40










              • thanks. It worked for me.
                – Däñish Shärmà
                Apr 27 at 14:40















              up vote
              22
              down vote













              I have been looking for the solution to this question from last couple of days myself. After tearing my hairs out for hours I have finally found a simple workaround. What I have noticed is that if you have custom background set on EditText the android:paddingTop attribute simple doesn't work to alter the spacing b/w the hint text and edit text (I have really no idea why). So if you have set custom background to your EditText, you can use android:translationY attribute in the EditText.



              So here's your solution:



              <android.support.design.widget.TextInputLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:layout_marginRight="30dp"
              android:layout_marginTop="10dp"
              app:hintTextAppearance="@style/TextHint">

              <EditText
              android:id="@+id/edttxtEmailAddress"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:background="@drawable/rounded_common"
              android:hint="@string/enter_valid_email"
              android:paddingLeft="20dp"

              android:translationY="10dp"

              android:singleLine="true"
              android:textSize="20sp" />
              </android.support.design.widget.TextInputLayout>


              Hope it helps. :)





              Update: My sincerest apologies for the late update. I have been really busy lately. If you haven't realized yet let me tell you this answer is straight out ugly and wrong. In retrospect I think I was probably drunk when I wrote it. As mentioned by others it might cut the bottom region of the editText background but there's an ugly fix for it as well - you can set the height of the (parent) textInputLayout sightly bigger (how big? you are supposed to find it by trial and error, yuck!) than the (child) editText. I hope you all do realize that would be crazy so please don't do it. Check out the answer written by @Radu Topor, it's by far the best and clean solution to this question. Thanks.






              share|improve this answer























              • Great its working thx dude...
                – Pranav
                Sep 28 '15 at 14:27










              • saved my life :) Thanks man!
                – Muhammad Riyaz
                Mar 15 '16 at 11:17










              • Thank you very much!
                – DmitryKanunnikoff
                May 16 '17 at 21:46










              • well its affecting the background layout set in edittext
                – Vicky
                Jul 31 '17 at 8:40










              • thanks. It worked for me.
                – Däñish Shärmà
                Apr 27 at 14:40













              up vote
              22
              down vote










              up vote
              22
              down vote









              I have been looking for the solution to this question from last couple of days myself. After tearing my hairs out for hours I have finally found a simple workaround. What I have noticed is that if you have custom background set on EditText the android:paddingTop attribute simple doesn't work to alter the spacing b/w the hint text and edit text (I have really no idea why). So if you have set custom background to your EditText, you can use android:translationY attribute in the EditText.



              So here's your solution:



              <android.support.design.widget.TextInputLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:layout_marginRight="30dp"
              android:layout_marginTop="10dp"
              app:hintTextAppearance="@style/TextHint">

              <EditText
              android:id="@+id/edttxtEmailAddress"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:background="@drawable/rounded_common"
              android:hint="@string/enter_valid_email"
              android:paddingLeft="20dp"

              android:translationY="10dp"

              android:singleLine="true"
              android:textSize="20sp" />
              </android.support.design.widget.TextInputLayout>


              Hope it helps. :)





              Update: My sincerest apologies for the late update. I have been really busy lately. If you haven't realized yet let me tell you this answer is straight out ugly and wrong. In retrospect I think I was probably drunk when I wrote it. As mentioned by others it might cut the bottom region of the editText background but there's an ugly fix for it as well - you can set the height of the (parent) textInputLayout sightly bigger (how big? you are supposed to find it by trial and error, yuck!) than the (child) editText. I hope you all do realize that would be crazy so please don't do it. Check out the answer written by @Radu Topor, it's by far the best and clean solution to this question. Thanks.






              share|improve this answer














              I have been looking for the solution to this question from last couple of days myself. After tearing my hairs out for hours I have finally found a simple workaround. What I have noticed is that if you have custom background set on EditText the android:paddingTop attribute simple doesn't work to alter the spacing b/w the hint text and edit text (I have really no idea why). So if you have set custom background to your EditText, you can use android:translationY attribute in the EditText.



              So here's your solution:



              <android.support.design.widget.TextInputLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:layout_marginRight="30dp"
              android:layout_marginTop="10dp"
              app:hintTextAppearance="@style/TextHint">

              <EditText
              android:id="@+id/edttxtEmailAddress"
              android:layout_width="match_parent"
              android:layout_height="50dp"
              android:background="@drawable/rounded_common"
              android:hint="@string/enter_valid_email"
              android:paddingLeft="20dp"

              android:translationY="10dp"

              android:singleLine="true"
              android:textSize="20sp" />
              </android.support.design.widget.TextInputLayout>


              Hope it helps. :)





              Update: My sincerest apologies for the late update. I have been really busy lately. If you haven't realized yet let me tell you this answer is straight out ugly and wrong. In retrospect I think I was probably drunk when I wrote it. As mentioned by others it might cut the bottom region of the editText background but there's an ugly fix for it as well - you can set the height of the (parent) textInputLayout sightly bigger (how big? you are supposed to find it by trial and error, yuck!) than the (child) editText. I hope you all do realize that would be crazy so please don't do it. Check out the answer written by @Radu Topor, it's by far the best and clean solution to this question. Thanks.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 23 '17 at 12:26









              Community

              11




              11










              answered Sep 28 '15 at 11:39









              Ganesh Mohan

              751717




              751717












              • Great its working thx dude...
                – Pranav
                Sep 28 '15 at 14:27










              • saved my life :) Thanks man!
                – Muhammad Riyaz
                Mar 15 '16 at 11:17










              • Thank you very much!
                – DmitryKanunnikoff
                May 16 '17 at 21:46










              • well its affecting the background layout set in edittext
                – Vicky
                Jul 31 '17 at 8:40










              • thanks. It worked for me.
                – Däñish Shärmà
                Apr 27 at 14:40


















              • Great its working thx dude...
                – Pranav
                Sep 28 '15 at 14:27










              • saved my life :) Thanks man!
                – Muhammad Riyaz
                Mar 15 '16 at 11:17










              • Thank you very much!
                – DmitryKanunnikoff
                May 16 '17 at 21:46










              • well its affecting the background layout set in edittext
                – Vicky
                Jul 31 '17 at 8:40










              • thanks. It worked for me.
                – Däñish Shärmà
                Apr 27 at 14:40
















              Great its working thx dude...
              – Pranav
              Sep 28 '15 at 14:27




              Great its working thx dude...
              – Pranav
              Sep 28 '15 at 14:27












              saved my life :) Thanks man!
              – Muhammad Riyaz
              Mar 15 '16 at 11:17




              saved my life :) Thanks man!
              – Muhammad Riyaz
              Mar 15 '16 at 11:17












              Thank you very much!
              – DmitryKanunnikoff
              May 16 '17 at 21:46




              Thank you very much!
              – DmitryKanunnikoff
              May 16 '17 at 21:46












              well its affecting the background layout set in edittext
              – Vicky
              Jul 31 '17 at 8:40




              well its affecting the background layout set in edittext
              – Vicky
              Jul 31 '17 at 8:40












              thanks. It worked for me.
              – Däñish Shärmà
              Apr 27 at 14:40




              thanks. It worked for me.
              – Däñish Shärmà
              Apr 27 at 14:40










              up vote
              11
              down vote













              I tried the padding changes, but it doesn't work well.



              A simple workaround is to change the height of the TIL:



              android:layout_height="wrap_content"


              to (e.g.)



              android:layout_height="50dp"


              it might not give the same result on all screen sizes.



              And add



              android:gravity="bottom" 


              to push your text down.






              share|improve this answer























              • this is simplest solution
                – amorenew
                May 10 at 5:14















              up vote
              11
              down vote













              I tried the padding changes, but it doesn't work well.



              A simple workaround is to change the height of the TIL:



              android:layout_height="wrap_content"


              to (e.g.)



              android:layout_height="50dp"


              it might not give the same result on all screen sizes.



              And add



              android:gravity="bottom" 


              to push your text down.






              share|improve this answer























              • this is simplest solution
                – amorenew
                May 10 at 5:14













              up vote
              11
              down vote










              up vote
              11
              down vote









              I tried the padding changes, but it doesn't work well.



              A simple workaround is to change the height of the TIL:



              android:layout_height="wrap_content"


              to (e.g.)



              android:layout_height="50dp"


              it might not give the same result on all screen sizes.



              And add



              android:gravity="bottom" 


              to push your text down.






              share|improve this answer














              I tried the padding changes, but it doesn't work well.



              A simple workaround is to change the height of the TIL:



              android:layout_height="wrap_content"


              to (e.g.)



              android:layout_height="50dp"


              it might not give the same result on all screen sizes.



              And add



              android:gravity="bottom" 


              to push your text down.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 18 '16 at 13:31









              Oleksandr Bodashko

              1036




              1036










              answered Mar 31 '16 at 14:32









              axd

              502412




              502412












              • this is simplest solution
                – amorenew
                May 10 at 5:14


















              • this is simplest solution
                – amorenew
                May 10 at 5:14
















              this is simplest solution
              – amorenew
              May 10 at 5:14




              this is simplest solution
              – amorenew
              May 10 at 5:14










              up vote
              7
              down vote













              @RaduTopor 's answer is good, but I think we also need add android:bottom or else it also de-centres the hint text displayed inside the EditText when not focused



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


              Before(RaduTopor answer):



              not centered



              After:



              centered






              share|improve this answer





















              • Thanks this might be the best solution for that
                – Shhhhhhh
                Jul 5 at 5:12















              up vote
              7
              down vote













              @RaduTopor 's answer is good, but I think we also need add android:bottom or else it also de-centres the hint text displayed inside the EditText when not focused



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


              Before(RaduTopor answer):



              not centered



              After:



              centered






              share|improve this answer





















              • Thanks this might be the best solution for that
                – Shhhhhhh
                Jul 5 at 5:12













              up vote
              7
              down vote










              up vote
              7
              down vote









              @RaduTopor 's answer is good, but I think we also need add android:bottom or else it also de-centres the hint text displayed inside the EditText when not focused



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


              Before(RaduTopor answer):



              not centered



              After:



              centered






              share|improve this answer












              @RaduTopor 's answer is good, but I think we also need add android:bottom or else it also de-centres the hint text displayed inside the EditText when not focused



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


              Before(RaduTopor answer):



              not centered



              After:



              centered







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 28 '16 at 2:01









              Chandler

              9181816




              9181816












              • Thanks this might be the best solution for that
                – Shhhhhhh
                Jul 5 at 5:12


















              • Thanks this might be the best solution for that
                – Shhhhhhh
                Jul 5 at 5:12
















              Thanks this might be the best solution for that
              – Shhhhhhh
              Jul 5 at 5:12




              Thanks this might be the best solution for that
              – Shhhhhhh
              Jul 5 at 5:12










              up vote
              2
              down vote













              I made a special class for the purpose of adding empty view above EditText, thus add padding to hint. You can use it as simple TextInputLayout.



              public class PaddingTextInputLayout extends TextInputLayout {

              public View paddingView;

              public PaddingTextInputLayout(Context context) {
              super(context);
              }

              public PaddingTextInputLayout(Context context, AttributeSet attrs) {
              super(context, attrs);
              }

              public PaddingTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
              super(context, attrs, defStyleAttr);
              }

              @Override
              public void addView(View child, int index, ViewGroup.LayoutParams params) {
              super.addView(child, index, params);
              refreshPaddingView();
              }

              public void addPaddingView(){
              paddingView = new View(getContext());
              int height = (int) getContext().getResources()
              .getDimension(R.dimen.edittext_text_input_layout_padding);
              ViewGroup.LayoutParams paddingParams = new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT,
              height);
              super.addView(paddingView, 0, paddingParams);
              }

              public void refreshPaddingView(){
              if (paddingView != null) {
              removeView(paddingView);
              paddingView = null;
              }
              addPaddingView();
              }
              }


              This implementation is very simple and stupid, you can improve it a lot.






              share|improve this answer

























                up vote
                2
                down vote













                I made a special class for the purpose of adding empty view above EditText, thus add padding to hint. You can use it as simple TextInputLayout.



                public class PaddingTextInputLayout extends TextInputLayout {

                public View paddingView;

                public PaddingTextInputLayout(Context context) {
                super(context);
                }

                public PaddingTextInputLayout(Context context, AttributeSet attrs) {
                super(context, attrs);
                }

                public PaddingTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
                super(context, attrs, defStyleAttr);
                }

                @Override
                public void addView(View child, int index, ViewGroup.LayoutParams params) {
                super.addView(child, index, params);
                refreshPaddingView();
                }

                public void addPaddingView(){
                paddingView = new View(getContext());
                int height = (int) getContext().getResources()
                .getDimension(R.dimen.edittext_text_input_layout_padding);
                ViewGroup.LayoutParams paddingParams = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                height);
                super.addView(paddingView, 0, paddingParams);
                }

                public void refreshPaddingView(){
                if (paddingView != null) {
                removeView(paddingView);
                paddingView = null;
                }
                addPaddingView();
                }
                }


                This implementation is very simple and stupid, you can improve it a lot.






                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  I made a special class for the purpose of adding empty view above EditText, thus add padding to hint. You can use it as simple TextInputLayout.



                  public class PaddingTextInputLayout extends TextInputLayout {

                  public View paddingView;

                  public PaddingTextInputLayout(Context context) {
                  super(context);
                  }

                  public PaddingTextInputLayout(Context context, AttributeSet attrs) {
                  super(context, attrs);
                  }

                  public PaddingTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
                  super(context, attrs, defStyleAttr);
                  }

                  @Override
                  public void addView(View child, int index, ViewGroup.LayoutParams params) {
                  super.addView(child, index, params);
                  refreshPaddingView();
                  }

                  public void addPaddingView(){
                  paddingView = new View(getContext());
                  int height = (int) getContext().getResources()
                  .getDimension(R.dimen.edittext_text_input_layout_padding);
                  ViewGroup.LayoutParams paddingParams = new ViewGroup.LayoutParams(
                  ViewGroup.LayoutParams.MATCH_PARENT,
                  height);
                  super.addView(paddingView, 0, paddingParams);
                  }

                  public void refreshPaddingView(){
                  if (paddingView != null) {
                  removeView(paddingView);
                  paddingView = null;
                  }
                  addPaddingView();
                  }
                  }


                  This implementation is very simple and stupid, you can improve it a lot.






                  share|improve this answer












                  I made a special class for the purpose of adding empty view above EditText, thus add padding to hint. You can use it as simple TextInputLayout.



                  public class PaddingTextInputLayout extends TextInputLayout {

                  public View paddingView;

                  public PaddingTextInputLayout(Context context) {
                  super(context);
                  }

                  public PaddingTextInputLayout(Context context, AttributeSet attrs) {
                  super(context, attrs);
                  }

                  public PaddingTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
                  super(context, attrs, defStyleAttr);
                  }

                  @Override
                  public void addView(View child, int index, ViewGroup.LayoutParams params) {
                  super.addView(child, index, params);
                  refreshPaddingView();
                  }

                  public void addPaddingView(){
                  paddingView = new View(getContext());
                  int height = (int) getContext().getResources()
                  .getDimension(R.dimen.edittext_text_input_layout_padding);
                  ViewGroup.LayoutParams paddingParams = new ViewGroup.LayoutParams(
                  ViewGroup.LayoutParams.MATCH_PARENT,
                  height);
                  super.addView(paddingView, 0, paddingParams);
                  }

                  public void refreshPaddingView(){
                  if (paddingView != null) {
                  removeView(paddingView);
                  paddingView = null;
                  }
                  addPaddingView();
                  }
                  }


                  This implementation is very simple and stupid, you can improve it a lot.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 2 '16 at 11:43









                  P. Sukharev

                  265




                  265






















                      up vote
                      2
                      down vote













                      To disable the bottom line cut effect i have used margins, translationY and clipChildren="false"



                      <android.support.design.widget.TextInputLayout
                      android:id="@+id/textinput"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginEnd="8dp"
                      android:layout_marginStart="16dp"
                      android:layout_marginTop="8dp"
                      android:clipChildren="false">

                      <android.support.design.widget.TextInputEditText
                      android:id="@+id/et_profile_contact_name"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:layout_margin="3dp"
                      android:background="@drawable/image_back"
                      android:hint="Contact name"
                      android:padding="5dp"
                      android:translationY="3dp" />
                      </android.support.design.widget.TextInputLayout>





                      share|improve this answer

























                        up vote
                        2
                        down vote













                        To disable the bottom line cut effect i have used margins, translationY and clipChildren="false"



                        <android.support.design.widget.TextInputLayout
                        android:id="@+id/textinput"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginEnd="8dp"
                        android:layout_marginStart="16dp"
                        android:layout_marginTop="8dp"
                        android:clipChildren="false">

                        <android.support.design.widget.TextInputEditText
                        android:id="@+id/et_profile_contact_name"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_margin="3dp"
                        android:background="@drawable/image_back"
                        android:hint="Contact name"
                        android:padding="5dp"
                        android:translationY="3dp" />
                        </android.support.design.widget.TextInputLayout>





                        share|improve this answer























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          To disable the bottom line cut effect i have used margins, translationY and clipChildren="false"



                          <android.support.design.widget.TextInputLayout
                          android:id="@+id/textinput"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginEnd="8dp"
                          android:layout_marginStart="16dp"
                          android:layout_marginTop="8dp"
                          android:clipChildren="false">

                          <android.support.design.widget.TextInputEditText
                          android:id="@+id/et_profile_contact_name"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:layout_margin="3dp"
                          android:background="@drawable/image_back"
                          android:hint="Contact name"
                          android:padding="5dp"
                          android:translationY="3dp" />
                          </android.support.design.widget.TextInputLayout>





                          share|improve this answer












                          To disable the bottom line cut effect i have used margins, translationY and clipChildren="false"



                          <android.support.design.widget.TextInputLayout
                          android:id="@+id/textinput"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginEnd="8dp"
                          android:layout_marginStart="16dp"
                          android:layout_marginTop="8dp"
                          android:clipChildren="false">

                          <android.support.design.widget.TextInputEditText
                          android:id="@+id/et_profile_contact_name"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:layout_margin="3dp"
                          android:background="@drawable/image_back"
                          android:hint="Contact name"
                          android:padding="5dp"
                          android:translationY="3dp" />
                          </android.support.design.widget.TextInputLayout>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 2 '17 at 16:08









                          Pavel Poley

                          457317




                          457317






















                              up vote
                              1
                              down vote













                              Just add to your EditText custom background



                              <?xml version="1.0" encoding="utf-8"?>
                              <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
                              <item>
                              <shape android:shape="rectangle">
                              <padding
                              android:top="4dp"/> // your padding value
                              </shape>
                              </item>
                              // customize your background items if you need
                              </layer-list>
                              <android.support.design.widget.TextInputLayout
                              ...>
                              <android.support.design.widget.TextInputEditText
                              ...
                              android:background="@style/your_custom_background"/>


                              then apply it to your EditText and increase height of your EditText with your padding value if you use fix height






                              share|improve this answer

























                                up vote
                                1
                                down vote













                                Just add to your EditText custom background



                                <?xml version="1.0" encoding="utf-8"?>
                                <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
                                <item>
                                <shape android:shape="rectangle">
                                <padding
                                android:top="4dp"/> // your padding value
                                </shape>
                                </item>
                                // customize your background items if you need
                                </layer-list>
                                <android.support.design.widget.TextInputLayout
                                ...>
                                <android.support.design.widget.TextInputEditText
                                ...
                                android:background="@style/your_custom_background"/>


                                then apply it to your EditText and increase height of your EditText with your padding value if you use fix height






                                share|improve this answer























                                  up vote
                                  1
                                  down vote










                                  up vote
                                  1
                                  down vote









                                  Just add to your EditText custom background



                                  <?xml version="1.0" encoding="utf-8"?>
                                  <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
                                  <item>
                                  <shape android:shape="rectangle">
                                  <padding
                                  android:top="4dp"/> // your padding value
                                  </shape>
                                  </item>
                                  // customize your background items if you need
                                  </layer-list>
                                  <android.support.design.widget.TextInputLayout
                                  ...>
                                  <android.support.design.widget.TextInputEditText
                                  ...
                                  android:background="@style/your_custom_background"/>


                                  then apply it to your EditText and increase height of your EditText with your padding value if you use fix height






                                  share|improve this answer












                                  Just add to your EditText custom background



                                  <?xml version="1.0" encoding="utf-8"?>
                                  <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
                                  <item>
                                  <shape android:shape="rectangle">
                                  <padding
                                  android:top="4dp"/> // your padding value
                                  </shape>
                                  </item>
                                  // customize your background items if you need
                                  </layer-list>
                                  <android.support.design.widget.TextInputLayout
                                  ...>
                                  <android.support.design.widget.TextInputEditText
                                  ...
                                  android:background="@style/your_custom_background"/>


                                  then apply it to your EditText and increase height of your EditText with your padding value if you use fix height







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Aug 8 '17 at 8:20









                                  Alex Naumchick

                                  113




                                  113






















                                      up vote
                                      0
                                      down vote













                                      If the requirement is to add space between cursor and hint then you can try



                                      editTextComment.setHint("  "+getString(R.string.add_a_comment));





                                      share|improve this answer

























                                        up vote
                                        0
                                        down vote













                                        If the requirement is to add space between cursor and hint then you can try



                                        editTextComment.setHint("  "+getString(R.string.add_a_comment));





                                        share|improve this answer























                                          up vote
                                          0
                                          down vote










                                          up vote
                                          0
                                          down vote









                                          If the requirement is to add space between cursor and hint then you can try



                                          editTextComment.setHint("  "+getString(R.string.add_a_comment));





                                          share|improve this answer












                                          If the requirement is to add space between cursor and hint then you can try



                                          editTextComment.setHint("  "+getString(R.string.add_a_comment));






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Oct 12 at 9:00









                                          ashishdhiman2007

                                          1981315




                                          1981315






















                                              up vote
                                              0
                                              down vote













                                              This is what i did in my project for getting enough space between edittext and hint



                                              <android.support.design.widget.TextInputLayout
                                              android:id="@+id/til_full_name"
                                              android:layout_width="match_parent"
                                              android:layout_height="60dp"
                                              android:layout_marginStart="40dp"
                                              android:layout_marginEnd="40dp"
                                              android:layout_marginTop="30dp"
                                              android:gravity="bottom"
                                              android:textColorHint="#fff"
                                              app:layout_constraintTop_toBottomOf="@+id/welcome_til_email">

                                              <android.support.v7.widget.AppCompatEditText
                                              android:id="@+id/et_name"
                                              android:layout_width="match_parent"
                                              android:layout_height="40dp"
                                              android:background="#9a050505"
                                              android:hint="You email"
                                              android:inputType="textCapWords"
                                              android:paddingLeft="10dp"
                                              android:paddingRight="10dp"
                                              android:singleLine="true"
                                              android:textAppearance="?android:textAppearanceSmall"
                                              android:textColor="#fff"
                                              app:layout_constraintLeft_toLeftOf="parent"
                                              app:layout_constraintRight_toRightOf="parent" />
                                              </android.support.design.widget.TextInputLayout>





                                              share|improve this answer

























                                                up vote
                                                0
                                                down vote













                                                This is what i did in my project for getting enough space between edittext and hint



                                                <android.support.design.widget.TextInputLayout
                                                android:id="@+id/til_full_name"
                                                android:layout_width="match_parent"
                                                android:layout_height="60dp"
                                                android:layout_marginStart="40dp"
                                                android:layout_marginEnd="40dp"
                                                android:layout_marginTop="30dp"
                                                android:gravity="bottom"
                                                android:textColorHint="#fff"
                                                app:layout_constraintTop_toBottomOf="@+id/welcome_til_email">

                                                <android.support.v7.widget.AppCompatEditText
                                                android:id="@+id/et_name"
                                                android:layout_width="match_parent"
                                                android:layout_height="40dp"
                                                android:background="#9a050505"
                                                android:hint="You email"
                                                android:inputType="textCapWords"
                                                android:paddingLeft="10dp"
                                                android:paddingRight="10dp"
                                                android:singleLine="true"
                                                android:textAppearance="?android:textAppearanceSmall"
                                                android:textColor="#fff"
                                                app:layout_constraintLeft_toLeftOf="parent"
                                                app:layout_constraintRight_toRightOf="parent" />
                                                </android.support.design.widget.TextInputLayout>





                                                share|improve this answer























                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  This is what i did in my project for getting enough space between edittext and hint



                                                  <android.support.design.widget.TextInputLayout
                                                  android:id="@+id/til_full_name"
                                                  android:layout_width="match_parent"
                                                  android:layout_height="60dp"
                                                  android:layout_marginStart="40dp"
                                                  android:layout_marginEnd="40dp"
                                                  android:layout_marginTop="30dp"
                                                  android:gravity="bottom"
                                                  android:textColorHint="#fff"
                                                  app:layout_constraintTop_toBottomOf="@+id/welcome_til_email">

                                                  <android.support.v7.widget.AppCompatEditText
                                                  android:id="@+id/et_name"
                                                  android:layout_width="match_parent"
                                                  android:layout_height="40dp"
                                                  android:background="#9a050505"
                                                  android:hint="You email"
                                                  android:inputType="textCapWords"
                                                  android:paddingLeft="10dp"
                                                  android:paddingRight="10dp"
                                                  android:singleLine="true"
                                                  android:textAppearance="?android:textAppearanceSmall"
                                                  android:textColor="#fff"
                                                  app:layout_constraintLeft_toLeftOf="parent"
                                                  app:layout_constraintRight_toRightOf="parent" />
                                                  </android.support.design.widget.TextInputLayout>





                                                  share|improve this answer












                                                  This is what i did in my project for getting enough space between edittext and hint



                                                  <android.support.design.widget.TextInputLayout
                                                  android:id="@+id/til_full_name"
                                                  android:layout_width="match_parent"
                                                  android:layout_height="60dp"
                                                  android:layout_marginStart="40dp"
                                                  android:layout_marginEnd="40dp"
                                                  android:layout_marginTop="30dp"
                                                  android:gravity="bottom"
                                                  android:textColorHint="#fff"
                                                  app:layout_constraintTop_toBottomOf="@+id/welcome_til_email">

                                                  <android.support.v7.widget.AppCompatEditText
                                                  android:id="@+id/et_name"
                                                  android:layout_width="match_parent"
                                                  android:layout_height="40dp"
                                                  android:background="#9a050505"
                                                  android:hint="You email"
                                                  android:inputType="textCapWords"
                                                  android:paddingLeft="10dp"
                                                  android:paddingRight="10dp"
                                                  android:singleLine="true"
                                                  android:textAppearance="?android:textAppearanceSmall"
                                                  android:textColor="#fff"
                                                  app:layout_constraintLeft_toLeftOf="parent"
                                                  app:layout_constraintRight_toRightOf="parent" />
                                                  </android.support.design.widget.TextInputLayout>






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Nov 2 at 15:28









                                                  ArjunA

                                                  265




                                                  265






















                                                      up vote
                                                      0
                                                      down vote













                                                      This a late answer but hope it helps, And I thinks its a bit better solution. Rather then giving background to your editText , Give that background to your TextInputLayout . And set edittext layout to transparent.



                                                      <android.support.design.widget.TextInputLayout
                                                      android:id="@+id/tinput_phone"
                                                      android:layout_width="match_parent"
                                                      android:layout_height="wrap_content"
                                                      android:layout_marginTop="10dp"
                                                      android:layout_marginBottom="05dp"
                                                      android:background="@drawable/send_email_screen_element_bg"
                                                      android:padding="05dp"
                                                      android:theme="@style/grey_control_style">

                                                      <android.support.v7.widget.AppCompatEditText
                                                      android:id="@+id/edt_phone"
                                                      android:layout_width="match_parent"
                                                      android:layout_height="wrap_content"
                                                      android:background="@android:color/transparent"
                                                      android:ems="10"
                                                      android:hint="@string/phone_hint_str"
                                                      android:inputType="text"
                                                      android:paddingStart="10dp"
                                                      android:paddingTop="10dp"
                                                      android:paddingBottom="10dp"
                                                      android:singleLine="true"
                                                      android:textColor="@color/black"
                                                      android:textSize="14sp" />
                                                      </android.support.design.widget.TextInputLayout>





                                                      share|improve this answer

























                                                        up vote
                                                        0
                                                        down vote













                                                        This a late answer but hope it helps, And I thinks its a bit better solution. Rather then giving background to your editText , Give that background to your TextInputLayout . And set edittext layout to transparent.



                                                        <android.support.design.widget.TextInputLayout
                                                        android:id="@+id/tinput_phone"
                                                        android:layout_width="match_parent"
                                                        android:layout_height="wrap_content"
                                                        android:layout_marginTop="10dp"
                                                        android:layout_marginBottom="05dp"
                                                        android:background="@drawable/send_email_screen_element_bg"
                                                        android:padding="05dp"
                                                        android:theme="@style/grey_control_style">

                                                        <android.support.v7.widget.AppCompatEditText
                                                        android:id="@+id/edt_phone"
                                                        android:layout_width="match_parent"
                                                        android:layout_height="wrap_content"
                                                        android:background="@android:color/transparent"
                                                        android:ems="10"
                                                        android:hint="@string/phone_hint_str"
                                                        android:inputType="text"
                                                        android:paddingStart="10dp"
                                                        android:paddingTop="10dp"
                                                        android:paddingBottom="10dp"
                                                        android:singleLine="true"
                                                        android:textColor="@color/black"
                                                        android:textSize="14sp" />
                                                        </android.support.design.widget.TextInputLayout>





                                                        share|improve this answer























                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote









                                                          This a late answer but hope it helps, And I thinks its a bit better solution. Rather then giving background to your editText , Give that background to your TextInputLayout . And set edittext layout to transparent.



                                                          <android.support.design.widget.TextInputLayout
                                                          android:id="@+id/tinput_phone"
                                                          android:layout_width="match_parent"
                                                          android:layout_height="wrap_content"
                                                          android:layout_marginTop="10dp"
                                                          android:layout_marginBottom="05dp"
                                                          android:background="@drawable/send_email_screen_element_bg"
                                                          android:padding="05dp"
                                                          android:theme="@style/grey_control_style">

                                                          <android.support.v7.widget.AppCompatEditText
                                                          android:id="@+id/edt_phone"
                                                          android:layout_width="match_parent"
                                                          android:layout_height="wrap_content"
                                                          android:background="@android:color/transparent"
                                                          android:ems="10"
                                                          android:hint="@string/phone_hint_str"
                                                          android:inputType="text"
                                                          android:paddingStart="10dp"
                                                          android:paddingTop="10dp"
                                                          android:paddingBottom="10dp"
                                                          android:singleLine="true"
                                                          android:textColor="@color/black"
                                                          android:textSize="14sp" />
                                                          </android.support.design.widget.TextInputLayout>





                                                          share|improve this answer












                                                          This a late answer but hope it helps, And I thinks its a bit better solution. Rather then giving background to your editText , Give that background to your TextInputLayout . And set edittext layout to transparent.



                                                          <android.support.design.widget.TextInputLayout
                                                          android:id="@+id/tinput_phone"
                                                          android:layout_width="match_parent"
                                                          android:layout_height="wrap_content"
                                                          android:layout_marginTop="10dp"
                                                          android:layout_marginBottom="05dp"
                                                          android:background="@drawable/send_email_screen_element_bg"
                                                          android:padding="05dp"
                                                          android:theme="@style/grey_control_style">

                                                          <android.support.v7.widget.AppCompatEditText
                                                          android:id="@+id/edt_phone"
                                                          android:layout_width="match_parent"
                                                          android:layout_height="wrap_content"
                                                          android:background="@android:color/transparent"
                                                          android:ems="10"
                                                          android:hint="@string/phone_hint_str"
                                                          android:inputType="text"
                                                          android:paddingStart="10dp"
                                                          android:paddingTop="10dp"
                                                          android:paddingBottom="10dp"
                                                          android:singleLine="true"
                                                          android:textColor="@color/black"
                                                          android:textSize="14sp" />
                                                          </android.support.design.widget.TextInputLayout>






                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered 15 hours ago









                                                          Nouman Ghaffar

                                                          1,7711425




                                                          1,7711425






















                                                              up vote
                                                              -1
                                                              down vote













                                                              I think you should consider this:



                                                              The design library takes an interesting approach to customizing the EditText: it doesn’t change it directly. Instead, the TextInputLayout is used to wrap the EditText and provide the enhancements.



                                                              The first one, displaying a floating label when the user types something into the field, is done automagically. The TextInputLayout finds the EditText among its children and attaches itself as a TextWatcher, so it’s able to determine when the field has been modified and animates the movement of the hint from its regular place in the EditText to the floating label position above it.



                                                              The second enhancement, displaying the error message, requires a slight change in code. Instead of setting the error on the EditText, the error should be set on the TextInputLayout. That’s because there is no automatic way for the TextInputLayout to be notified when the error is set on the EditText.
                                                              Here’s what the layout might look like:



                                                              <android.support.design.widget.TextInputLayout
                                                              android:id="@+id/username_text_input_layout"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content">
                                                              <EditText
                                                              android:id="@+id/username_edit_text"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content"
                                                              android:hint="@string/username_hint"/>
                                                              </android.support.design.widget.TextInputLayout>


                                                              Note that both the EditText and TextInputLayout need layout IDs. In the fragment, we would need to configure the TextInputLayout to enable displaying errors:



                                                              TextInputLayout usernameTextInputLayout = (TextInputLayout) view.findViewById(R.id.username_text_input_layout);
                                                              usernameTextInputLayout.setErrorEnabled(true);
                                                              ...
                                                              usernameTextInputLayout.setError(R.string.username_required);





                                                              share|improve this answer























                                                              • let the hint appear in the Edit text
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:29










                                                              • No that not what i want,I use background to edit text its expand edittext border beyond its default limit so that hint overlapping the edittext. Is there any method or xml tag that can make margin between Hint and Edittext upper border?
                                                                – Pranav
                                                                Sep 16 '15 at 13:33










                                                              • android:paddingTop="20dp" or what ever suit you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:37










                                                              • and remove this tag android:layout_marginTop="10dp" in your TextinputLayout
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:38












                                                              • please mark this as answer if this helps you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:39















                                                              up vote
                                                              -1
                                                              down vote













                                                              I think you should consider this:



                                                              The design library takes an interesting approach to customizing the EditText: it doesn’t change it directly. Instead, the TextInputLayout is used to wrap the EditText and provide the enhancements.



                                                              The first one, displaying a floating label when the user types something into the field, is done automagically. The TextInputLayout finds the EditText among its children and attaches itself as a TextWatcher, so it’s able to determine when the field has been modified and animates the movement of the hint from its regular place in the EditText to the floating label position above it.



                                                              The second enhancement, displaying the error message, requires a slight change in code. Instead of setting the error on the EditText, the error should be set on the TextInputLayout. That’s because there is no automatic way for the TextInputLayout to be notified when the error is set on the EditText.
                                                              Here’s what the layout might look like:



                                                              <android.support.design.widget.TextInputLayout
                                                              android:id="@+id/username_text_input_layout"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content">
                                                              <EditText
                                                              android:id="@+id/username_edit_text"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content"
                                                              android:hint="@string/username_hint"/>
                                                              </android.support.design.widget.TextInputLayout>


                                                              Note that both the EditText and TextInputLayout need layout IDs. In the fragment, we would need to configure the TextInputLayout to enable displaying errors:



                                                              TextInputLayout usernameTextInputLayout = (TextInputLayout) view.findViewById(R.id.username_text_input_layout);
                                                              usernameTextInputLayout.setErrorEnabled(true);
                                                              ...
                                                              usernameTextInputLayout.setError(R.string.username_required);





                                                              share|improve this answer























                                                              • let the hint appear in the Edit text
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:29










                                                              • No that not what i want,I use background to edit text its expand edittext border beyond its default limit so that hint overlapping the edittext. Is there any method or xml tag that can make margin between Hint and Edittext upper border?
                                                                – Pranav
                                                                Sep 16 '15 at 13:33










                                                              • android:paddingTop="20dp" or what ever suit you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:37










                                                              • and remove this tag android:layout_marginTop="10dp" in your TextinputLayout
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:38












                                                              • please mark this as answer if this helps you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:39













                                                              up vote
                                                              -1
                                                              down vote










                                                              up vote
                                                              -1
                                                              down vote









                                                              I think you should consider this:



                                                              The design library takes an interesting approach to customizing the EditText: it doesn’t change it directly. Instead, the TextInputLayout is used to wrap the EditText and provide the enhancements.



                                                              The first one, displaying a floating label when the user types something into the field, is done automagically. The TextInputLayout finds the EditText among its children and attaches itself as a TextWatcher, so it’s able to determine when the field has been modified and animates the movement of the hint from its regular place in the EditText to the floating label position above it.



                                                              The second enhancement, displaying the error message, requires a slight change in code. Instead of setting the error on the EditText, the error should be set on the TextInputLayout. That’s because there is no automatic way for the TextInputLayout to be notified when the error is set on the EditText.
                                                              Here’s what the layout might look like:



                                                              <android.support.design.widget.TextInputLayout
                                                              android:id="@+id/username_text_input_layout"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content">
                                                              <EditText
                                                              android:id="@+id/username_edit_text"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content"
                                                              android:hint="@string/username_hint"/>
                                                              </android.support.design.widget.TextInputLayout>


                                                              Note that both the EditText and TextInputLayout need layout IDs. In the fragment, we would need to configure the TextInputLayout to enable displaying errors:



                                                              TextInputLayout usernameTextInputLayout = (TextInputLayout) view.findViewById(R.id.username_text_input_layout);
                                                              usernameTextInputLayout.setErrorEnabled(true);
                                                              ...
                                                              usernameTextInputLayout.setError(R.string.username_required);





                                                              share|improve this answer














                                                              I think you should consider this:



                                                              The design library takes an interesting approach to customizing the EditText: it doesn’t change it directly. Instead, the TextInputLayout is used to wrap the EditText and provide the enhancements.



                                                              The first one, displaying a floating label when the user types something into the field, is done automagically. The TextInputLayout finds the EditText among its children and attaches itself as a TextWatcher, so it’s able to determine when the field has been modified and animates the movement of the hint from its regular place in the EditText to the floating label position above it.



                                                              The second enhancement, displaying the error message, requires a slight change in code. Instead of setting the error on the EditText, the error should be set on the TextInputLayout. That’s because there is no automatic way for the TextInputLayout to be notified when the error is set on the EditText.
                                                              Here’s what the layout might look like:



                                                              <android.support.design.widget.TextInputLayout
                                                              android:id="@+id/username_text_input_layout"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content">
                                                              <EditText
                                                              android:id="@+id/username_edit_text"
                                                              android:layout_width="match_parent"
                                                              android:layout_height="wrap_content"
                                                              android:hint="@string/username_hint"/>
                                                              </android.support.design.widget.TextInputLayout>


                                                              Note that both the EditText and TextInputLayout need layout IDs. In the fragment, we would need to configure the TextInputLayout to enable displaying errors:



                                                              TextInputLayout usernameTextInputLayout = (TextInputLayout) view.findViewById(R.id.username_text_input_layout);
                                                              usernameTextInputLayout.setErrorEnabled(true);
                                                              ...
                                                              usernameTextInputLayout.setError(R.string.username_required);






                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Sep 16 '15 at 13:42









                                                              Mauker

                                                              7,66053658




                                                              7,66053658










                                                              answered Sep 16 '15 at 13:27









                                                              Coas Mckey

                                                              235532




                                                              235532












                                                              • let the hint appear in the Edit text
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:29










                                                              • No that not what i want,I use background to edit text its expand edittext border beyond its default limit so that hint overlapping the edittext. Is there any method or xml tag that can make margin between Hint and Edittext upper border?
                                                                – Pranav
                                                                Sep 16 '15 at 13:33










                                                              • android:paddingTop="20dp" or what ever suit you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:37










                                                              • and remove this tag android:layout_marginTop="10dp" in your TextinputLayout
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:38












                                                              • please mark this as answer if this helps you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:39


















                                                              • let the hint appear in the Edit text
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:29










                                                              • No that not what i want,I use background to edit text its expand edittext border beyond its default limit so that hint overlapping the edittext. Is there any method or xml tag that can make margin between Hint and Edittext upper border?
                                                                – Pranav
                                                                Sep 16 '15 at 13:33










                                                              • android:paddingTop="20dp" or what ever suit you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:37










                                                              • and remove this tag android:layout_marginTop="10dp" in your TextinputLayout
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:38












                                                              • please mark this as answer if this helps you
                                                                – Coas Mckey
                                                                Sep 16 '15 at 13:39
















                                                              let the hint appear in the Edit text
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:29




                                                              let the hint appear in the Edit text
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:29












                                                              No that not what i want,I use background to edit text its expand edittext border beyond its default limit so that hint overlapping the edittext. Is there any method or xml tag that can make margin between Hint and Edittext upper border?
                                                              – Pranav
                                                              Sep 16 '15 at 13:33




                                                              No that not what i want,I use background to edit text its expand edittext border beyond its default limit so that hint overlapping the edittext. Is there any method or xml tag that can make margin between Hint and Edittext upper border?
                                                              – Pranav
                                                              Sep 16 '15 at 13:33












                                                              android:paddingTop="20dp" or what ever suit you
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:37




                                                              android:paddingTop="20dp" or what ever suit you
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:37












                                                              and remove this tag android:layout_marginTop="10dp" in your TextinputLayout
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:38






                                                              and remove this tag android:layout_marginTop="10dp" in your TextinputLayout
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:38














                                                              please mark this as answer if this helps you
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:39




                                                              please mark this as answer if this helps you
                                                              – Coas Mckey
                                                              Sep 16 '15 at 13:39


















                                                               

                                                              draft saved


                                                              draft discarded



















































                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f32609710%2ftextinputlayout-how-to-give-padding-or-margin-to-hint%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                                                              Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                                                              A Topological Invariant for $pi_3(U(n))$