Android MaterialButton无法正确显示

时间:2019-09-25 17:36:04

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

我正在尝试使用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>

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

enter image description here

1 个答案:

答案 0 :(得分:1)

来自Docs

  

更改您的应用程序主题以从“材料组件”主题

继承
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 Components Bridge主题继承。

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

桥梁主题继承自 AppCompat主题,但也为您定义了新的“材料组件”主题属性。