【问题标题】:Style error when using Material ExposedDropdownMenu使用 Material ExposedDropdownMenu 时出现样式错误
【发布时间】:2019-10-10 23:06:23
【问题描述】:

当我尝试使用时

@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu 

Android Studio 要求我创建样式

<android.support.design.widget.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Type frais"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginEnd="8dp"
        >

    <AutoCompleteTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
</android.support.design.widget.TextInputLayout>

我希望在TextInputLayout 中看到ExposedDropdownMenu 样式,但实际上Android Studio 要求我创建这种样式

【问题讨论】:

    标签: android material-design android-textinputlayout material-components-android


    【解决方案1】:

    发布版本中引入了Exposed Dropdown Menu材质组件:

    1.1.0-alpha06

    深色主题、暴露的下拉菜单、徽章等等!

    来源:https://github.com/material-components/material-components-android/releases/tag/1.1.0-alpha06

    【讨论】:

      【解决方案2】:

      不要忘记将implementation 'com.google.android.material:material:&lt;desired version&gt;' 添加到您的应用 gradle 文件中(我就是这样)。

      更多信息,您可以参考Getting started with Material Components for Android doc

      【讨论】:

        【解决方案3】:

        改变

            <android.support.design.widget.TextInputLayout
                    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
                    ...>
        

        <com.google.android.material.textfield.TextInputLayout      
         style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
                 ...>
        

        com.google.android.material.textfield.TextInputLayout 包含在Material Components Library 中。

        【讨论】:

          【解决方案4】:

          第 1 步:在 app gradle 中添加依赖项:

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

          第 2 步:更改/修改应用级主题。

           <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
              <!-- Customize your theme here. -->
              <item name="windowNoTitle">true</item>
              <item name="windowActionBar">false</item>
          
              <item name="colorPrimary">@color/colorPrimary</item>
              <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
              <item name="colorAccent">@color/colorAccent</item>
          </style>
          

          第 3 步:然后在您的应用中使用材质控件。

           <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="District">
          
                              <androidx.appcompat.widget.AppCompatAutoCompleteTextView
                                  android:id="@+id/actDistrict"
                                  android:layout_width="match_parent"
                                  android:layout_height="wrap_content" />
          
                          </com.google.android.material.textfield.TextInputLayout>
          

          【讨论】:

            猜你喜欢
            • 2021-09-22
            • 2018-06-06
            • 2020-07-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-07-01
            • 2021-10-10
            • 1970-01-01
            相关资源
            最近更新 更多