问题描述
根据Material.IO的建议,我有一个ExposedDropDownMenu
作为微调器。我的问题是View.Gone
不起作用,并且在视图中留下了箭头,因此仍然占据空间。
屏幕截图
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