在上图中,密码字段位于TextInputLayout中,它的右侧还有一个TextView,它指向“忘记密码”活动。
我使用相对布局在没有TextInpt布局的情况下使用Textview实现EditText
XML布局:
<EditText
android:id="@+id/email_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_email"
android:drawableStart="@drawable/ic_email"
android:drawablePadding="10dp"
android:hint="@string/email_address"
android:textSize="14sp"
android:maxLines="1"
android:inputType="textEmailAddress" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/etxt_password_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_password"
android:drawableStart="@drawable/ic_password"
android:drawablePadding="10dp"
android:textSize="14sp"
android:hint="Password"
android:layout_alignParentLeft="true"
android:inputType="textPassword"
android:maxLines="1"/>
<TextView
android:id="@+id/txt_forget_password"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="forget ?"
android:textSize="12sp"
android:layout_marginRight="10dp"
android:textColor="#808080"
/>
</RelativeLayout>
但是,如果我在EditText中添加TextInputLayout,则无法实现。
我该如何解决这个问题?
像这样尝试-使用相对或线性布局环绕以获得类似的输出
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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:hint="Password"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Forgot Password ?"/>
</RelativeLayout>
注意:为编辑文本设置一些填充权以对齐
如果键入完整edittext,则字符的textview会覆盖。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句