有材质按钮,样式:
<style name="InstallButtonStyle" parent="Widget.MaterialComponents.Button">
<item name="materialThemeOverlay">@style/InstallButtonThemeOverlay</item>
</style>
<style name="InstallButtonThemeOverlay">
<item name="colorPrimary">@color/btn_color</item>
</style>
颜色是蓝色:
<color name="btn_color">#E6188FFF</color>
它一直在工作,但是当aar被用在一个不使用他们的材料的应用程序中时,应用程序崩溃了,
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class com.google.android.material.button.MaterialButton
必须添加
android:theme="@style/Theme.MaterialComponents.DayNight"
<com.google.android.material.button.MaterialButton
android:theme="@style/Theme.MaterialComponents.DayNight"
android:id="@id/btn"
style="@style/InstallButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
app:cornerRadius="20dp"
android:layout_gravity="bottom|right"
android:text="Install Now"
android:textAllCaps="false"/>