dtz*_*a34 11 android material-components material-components-android
我试图创建一个AutoCompleteTextView,被一个TextInputLayout. 根据文档,我应该使用这种风格:
Widget.MaterialComponents.TextInputLayout.*.ExposedDropdownMenu
Run Code Online (Sandbox Code Playgroud)
但我无法解决这种风格。Android Studio 说我只能使用:
@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense
@style/Widget.MaterialComponents.TextInputLayout.FilledBox
@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense
@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox
Run Code Online (Sandbox Code Playgroud)
我的项目使用
implementation 'com.android.support:design:28.0.0'
Run Code Online (Sandbox Code Playgroud)
最终结果应如下所示:
Widget.MaterialComponents.TextInputLayout.*.ExposedDropdownMenu
Run Code Online (Sandbox Code Playgroud)
Adi*_*i B 12
我在 Android Material Components 的 Github 问题中提出了这个问题。
基于此响应,公共文档不是基于当前的稳定版本,而是基于最新的 alpha(或 beta)版本。无法从 material.io 上的文档中得知哪些组件处于稳定、alpha 或 beta 版本的库中。
澄清后,此问题的解决方案是升级您的支持设计库,如@jeel-vankhede 所建议的那样:
implementation 'com.google.android.material:material:1.1.0-alpha07'
Run Code Online (Sandbox Code Playgroud)
相关的注意事项,如果您还使用 ViewModels (lib v. 2.0.0):
升级到 Material design 库的 1.1.0-alpha 会自动将 androidx.lifecycle 库更新到 2.1.0+。此更新与 2.0.0 相比有重大更改,可能会破坏您的视图模型代码。此更改仅在应用程序的缩小版本中观察到。
小智 6
并且不要忘记在您的应用程序中使用 Theme.MaterialComponents
AndroidManifest.xml
<application
android:theme="@style/AppTheme"
...
Run Code Online (Sandbox Code Playgroud)
样式文件
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)
小智 6
根据这个问题,*文档中的 表示使用任何样式TextInputLayout,例如FilledBox或OutlinedBox。此外,它在 1.1.0 版本中尚不可用,因此我使用此依赖项成功使其工作:
implementation 'com.google.android.material:material:1.2.0-alpha06'
Run Code Online (Sandbox Code Playgroud)
以及这两种样式中的任何一种(请记住在应用程序中使用 Theme.MaterialComponents,如 @R3mx 提到的):
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
Run Code Online (Sandbox Code Playgroud)
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
Run Code Online (Sandbox Code Playgroud)