我EditText
在 XML 文件中声明了一个自定义,我将其包括在内:
<include layout="@layout/my_edit_text"
android:id="@+id/passwordField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/passwordHint"
android:inputType="textPassword" />
这是my_edit_text.xml
:
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="0dp"
android:textColor="@color/gray"
android:textSize="@dimen/editTextFontSize"
android:padding="@dimen/editTextPadding"
android:background="@drawable/edit_text_background"
android:ellipsize="end" />
但是,由于某种原因,我无法设置hint
or这种方式。inputType
如果我将它设置为my_edit_text.xml
,它可以正常工作,但我希望能够单独设置每个引用。
我有这个习惯的原因EditText
是为了避免在我的每一个EditText
s 中重写所有的共同值。
我是否必须做与此人类似的事情?如果我这样做,我是否需要实际构建一个 .java 子类并以这种方式提取属性?这似乎太过分了。