【问题标题】:Android: View.Gone not working for AutoCompleteTextview as ExposedDropdownMenuAndroid:View.Gone 不适用于 AutoCompleteTextview 作为 ExposedDropdownMenu
【发布时间】:2020-08-21 16:57:13
【问题描述】:

我有一个 ExposedDropDownMenu 作为 Material.IO 推荐的 Spinner。我的问题是,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

感谢您的帮助。谢谢!

【问题讨论】:

    标签: android kotlin autocompletetextview material-components-android android-textinputlayout


    【解决方案1】:

    您可以尝试隐藏 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
    

    【讨论】:

    • 哇哦,确实奏效了。我很惊讶,因为我之前确实尝试过,但没有。谢谢!
    【解决方案2】:

    如果您想删除下拉图标,只需使用:

    textInputLayout.endIconMode = TextInputLayout.END_ICON_NONE
    

    【讨论】:

    • 不,我想删除整个布局,而不仅仅是箭头。
    猜你喜欢
    • 2016-12-20
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2017-07-22
    • 2015-04-20
    相关资源
    最近更新 更多