【发布时间】:2020-08-06 19:05:50
【问题描述】:
我想自定义一个MultiAutoCompleteTextView,为了使用Material,为了底层代码的可重用性和可更新性,它将被放置在TextInputLayout中。
我还没有开始,但我已经遇到了问题。
Graphic demostration of the problem
如您所见,第一个TextInputLayout 是完全错误的。
它们都具有完全相同的结构和属性,唯一不同的是自定义视图。
它基本上是一个扩展 MultiAutoCompleteTextView 的空类。
下面是xml和自定义视图类。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/custom_view"
style="@style/Theme.CustomViews.MorphInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/standard_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed">
<com.scitalys.customViews.ui.main.MorphInputText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/standard_view"
style="@style/Theme.CustomViews.MorphInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/custom_view">
<MultiAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint" />
</com.google.android.material.textfield.TextInputLayout>
class MorphInputText @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView(context, attrs, defStyleAttr) {
init {
this.threshold = 1
val textWatcher = MorphInputTextWatcher
this.addTextChangedListener(textWatcher)
}
}
【问题讨论】:
标签: android material-ui android-custom-view android-textinputlayout multiautocompletetextview