android–TextInputLayout:如何给出填充或边距提示?

android–TextInputLayout:如何给出填充或边距提示?,第1张

概述我必须在我的项目中使用设计支持库的TextInputLayout.我想在TextInputLayout中的提示和EditText之间给出空格.我在TextInputLayout中设置了margin和padding,甚至在EditText里面,但两者都不起作用.所以如何解决这个问题.在这里我附上屏幕截图和我的编码.=========================

我必须在我的项目中使用设计支持库的TextinputLayout.我想在TextinputLayout中的提示和EditText之间给出空格.我在TextinputLayout中设置了margin和padding,甚至在EditText里面,但两者都不起作用.所以如何解决这个问题.在这里我附上屏幕截图和我的编码.

==============================Style=================================<style name="TextHint" parent="Base.TextAppearance.AppCompat">    <item name="androID:textSize">18sp</item>    <item name="androID:textcolor">@color/green</item></style>=============================XML===================================  <androID.support.design.Widget.TextinputLayout    androID:layout_wIDth="match_parent"    app:hintTextAppearance="@style/TextHint"    androID:layout_margintop="10dp"    androID:layout_marginleft="30dp"    androID:layout_marginRight="30dp"    androID:layout_height="wrap_content"><EditText    androID:layout_wIDth="match_parent"    androID:layout_height="50dp"    androID:ID="@+ID/edttxtEmailAddress"    androID:singleline="true"    androID:hint="@string/enter_valID_email"    androID:paddingleft="20dp"    androID:textSize="20sp"    androID:background="@drawable/rounded_common"/></androID.support.design.Widget.TextinputLayout>

解决方法:

ganesh2shiv提出的解决方案在很大程度上起作用,尽管我发现它还会在不聚焦时将EditText内显示的提示文本去中心化.

更好的技巧是将所需的paddingtop设置为EditText,但也将额外的填充嵌入EditText的背景中.一个相当明智的方法是将原始背景包装在< @R_468_3419@>中.并设置< item androID:top =“...”>用于匹配EditText的paddingtop的属性.

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

和bg_edit_text.xml可绘制文件:

<@R_468_3419@ 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></@R_468_3419@>
总结

以上是内存溢出为你收集整理的android – TextInputLayout:如何给出填充或边距提示?全部内容,希望文章能够帮你解决android – TextInputLayout:如何给出填充或边距提示?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1102661.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存