11

我试图创建一个AutoCompleteTextView,被一个包围TextInputLayout。根据文档,我应该使用这种风格:

Widget.MaterialComponents.TextInputLayout.*.ExposedDropdownMenu 

但我无法解决这种风格。Android Studio 说我只能使用:

@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense
@style/Widget.MaterialComponents.TextInputLayout.FilledBox
@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense
@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox

我的项目使用

implementation 'com.android.support:design:28.0.0'

最终结果应如下所示:

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/hint_text">

  <AutoCompleteTextView
      android:id="@+id/filled_exposed_dropdown"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

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

4 回答 4

12

我在 Android Material Components 的 Github 问题中提出了这个查询。

基于此响应,公共文档不是基于当前的稳定版本,而是基于最新的 alpha(或 beta)版本。无法从 material.io 上的文档中得知哪些组件处于库的稳定、alpha 或 beta 版本中。

澄清后,此问题的解决方案是升级您的支持设计库,如@jeel-vankhede 建议的那样:

implementation 'com.google.android.material:material:1.1.0-alpha07'

相关提示,如果您还使用 ViewModels (lib v. 2.0.0):

升级到 Material design library 的 1.1.0-alpha 会自动将 androidx.lifecycle 库更新到 2.1.0+。此更新与 2.0.0 相比有一个重大更改,可能会破坏您的视图模型代码。此更改仅在应用程序的缩小版本中观察到。

于 2019-06-18T14:52:39.367 回答
6

并且不要忘记在您的应用程序中使用 Theme.MaterialComponents

AndroidManifest.xml

<application
    android:theme="@style/AppTheme"
    ...

样式.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
于 2019-10-21T09:48:53.143 回答
4

根据这个问题*文档中的 意味着使用来自的任何样式TextInputLayout,例如FilledBoxOutlinedBox。此外,它在 1.1.0 版本中尚不可用,因此我使用此依赖项成功使其工作:

implementation 'com.google.android.material:material:1.2.0-alpha06'

以及这两种样式中的任何一种(请记住在您的应用程序中使用 Theme.MaterialComponents,如@R3mx 所述):

style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
于 2020-04-28T11:02:09.187 回答
0

您现在可以使用

implementation 'com.google.android.material:material:1.2.0-alpha05'
于 2020-03-12T15:32:58.797 回答