Android: View.Gone 不适用于 AutoCompleteTextview 作为 ExposedDropdownMenu
Android: View.Gone not working for AutoCompleteTextview as ExposedDropdownMenu
根据 Material.IO 的推荐,我有一个 ExposedDropDownMenu
作为 Spinner。我的问题是,View.Gone
不起作用并在视图中留下一个箭头,因此仍然占用 space。
截图
XML
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/calibrate_message_dropdown_menu_TWO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
代码
calibrate_message_dropdown_menu_TWO.visibility = View.GONE
感谢任何帮助。谢谢!
您能否尝试隐藏 TextInputLayout 而不是包含的 AutoCompleteTextView。像这样为外部 TextInputLayout 添加一个 id:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:id="@+id/dropdown_layout"
android:layout_width="0dp"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/calibrate_message_dropdown_menu_TWO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
然后在代码中:
dropdown_layout.visibility = View.GONE
如果您想删除下拉图标,只需使用:
textInputLayout.endIconMode = TextInputLayout.END_ICON_NONE
根据 Material.IO 的推荐,我有一个 ExposedDropDownMenu
作为 Spinner。我的问题是,View.Gone
不起作用并在视图中留下一个箭头,因此仍然占用 space。
截图
XML
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/calibrate_message_dropdown_menu_TWO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
代码
calibrate_message_dropdown_menu_TWO.visibility = View.GONE
感谢任何帮助。谢谢!
您能否尝试隐藏 TextInputLayout 而不是包含的 AutoCompleteTextView。像这样为外部 TextInputLayout 添加一个 id:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:id="@+id/dropdown_layout"
android:layout_width="0dp"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/calibrate_message_dropdown_menu_TWO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
然后在代码中:
dropdown_layout.visibility = View.GONE
如果您想删除下拉图标,只需使用:
textInputLayout.endIconMode = TextInputLayout.END_ICON_NONE