TextInputLayout :How to give padding or margin to hint?

后端 未结 15 1866
离开以前
离开以前 2020-11-28 06:42

I have to use TextInputLayout of design support library in my project. I want to give space between hint and EditText in TextInp

15条回答
  •  迷失自我
    2020-11-28 07:31

    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:

    
    
        
    
    

    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.

提交回复
热议问题