【问题标题】:Android MaterialButton not displaying correctlyAndroid MaterialButton 无法正确显示
【发布时间】:2020-01-25 23:10:39
【问题描述】:

我正在尝试使用 MaterialButton,但它不能正常工作。 我的 androidx 依赖

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha10'

我的 test.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        app:strokeColor="@color/colorPrimary"/>

</LinearLayout>

还有我的按钮截图,为什么样式不起作用??

【问题讨论】:

  • 发布您的应用主题

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


【解决方案1】:

来自Docs

更改您的应用主题以继承 Material Components 主题

Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar

如果您无法将主题更改为从 Material 组件继承 主题,您可以从 Material Components Bridge 主题继承。

Theme.MaterialComponents.Bridge
Theme.MaterialComponents.Light.Bridge
Theme.MaterialComponents.NoActionBar.Bridge
Theme.MaterialComponents.Light.NoActionBar.Bridge
Theme.MaterialComponents.Light.DarkActionBar.Bridge  

Bridge 主题 继承自 AppCompat 主题,但还为您定义了新的 Material Components 主题 属性。

【讨论】:

  • 它可以在较低的 Android API 上工作吗?如果我使用这个主题
猜你喜欢
  • 2021-01-10
  • 2019-10-09
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多