我正在使用它来显示textinputlayout的旋转器类型的视图,但是我不知道如何设置它的默认值。
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextColor="@color/primary_color_3">
<AutoCompleteTextView
android:id="@+id/accType_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/transparent"
android:inputType="none"
android:lineSpacingExtra="5sp"
android:textColor="@color/name_primary_color"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
占位符只工作时,它是在焦点模式,所以请建议我一个解决办法。
在AutoCompleteTextView
上使用Android:text
属性,如下所示
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextColor="@color/primary_color_3">
<AutoCompleteTextView
android:id="@+id/accType_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Something"
android:backgroundTint="@android:color/transparent"
android:inputType="none"
android:lineSpacingExtra="5sp"
android:textColor="@color/name_primary_color"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
AutoCompleteTextView
可以与适配器
一起工作。
只是举个例子:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til"
创建适配器:
ArrayList<String> items = new ArrayList<>();
items.add("Material");
items.add("Design");
items.add("Components");
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,R.layout.item, items);
TextInputLayout textInputLayout = findViewById(R.id.til);
设置默认值和适配器:
((MaterialAutoCompleteTextView) textInputLayout.getEditText()).setText(items.get(1));
((MaterialAutoCompleteTextView) textInputLayout.getEditText()).setAdapter(adapter);