【问题标题】:"inputType="none" doesn't work with Material Components ExposedDropdownMenu"inputType="none" 不适用于材质组件 ExposedDropdownMenu
【发布时间】:2020-05-03 20:23:29
【问题描述】:

我正在尝试按照此处找到的“实施公开的下拉菜单”下的指南制作一个不可编辑的公开下拉菜单:https://material.io/develop/android/components/text-fields/

但是,它仍然是可编辑的,即使在 AutoCompleteTextView 上使用“inputType="none"”。

这是我的 xml:

<com.google.android.material.textfield.TextInputLayout
            android:id="@+id/textInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="24dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">

            <AutoCompleteTextView
                android:id="@+id/autoCompleteTextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="none" />

</com.google.android.material.textfield.TextInputLayout>

有人知道为什么这不起作用,即使它在他们的官方文档中,以及如何使它真正不可编辑?

PS: "editable="false"" 确实解决了这个问题,但是由于它已被废弃,我真的不想使用它

【问题讨论】:

    标签: android material-components-android


    【解决方案1】:

    这个怎么样:

    android:focusable="false"
    android:focusableInTouchMode="false"
    android:inputType="none|textNoSuggestions"
    android:cursorVisible="false"
    

    【讨论】:

    • 谢谢,它有效!虽然我删除了两个可聚焦标签并在代码中添加了“showSoftInputOnFocus = false”,所以当聚焦时,暴露的下拉菜单仍然会着色。
    猜你喜欢
    • 2021-02-05
    • 2020-08-15
    • 2020-12-29
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2020-03-06
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多