更新库以支持 AndroidX
Update libraries to support AndroidX
目前我正在更新我的项目以支持 AndroidX。
我已将所有库重构为新的 androidx
- 库。
尽管如此,仍然有一些依赖项,例如 com.wdullaer:materialdatetimepicker
,它们不会被更新,并且在 UI.
中以一种看起来非常丑陋的方式显示
如何强制这些按钮使用新的 material 库?
我启用了选项
android.useAndroidX=true
android.enableJetifier=true
但如前所述,它不会影响这些库。
答案可以这么简单:
Material Components replaces all instances of Button with an instance
of MaterialButton when using one of its regular themes:
https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#material-components-themes
The default version of MaterialButton uses colorPrimary as the
background color. Because Material Components replaces the View
replacer with their own implementation there is not much I can do to
fix this from this library.
There are two workarounds:
Use one of the bridge themes, which do not replace the View Inflater
Overwrite the View inflater again in your application theme by adding
the following statement in your application theme: androidx.appcompat.app.AppCompatViewInflater
You will then need to explicitly use MaterialButton in your
application rather than Button
所以您基本上要做的就是将此行添加到您的应用程序主题中。然后,Material 组件将不再被替换。瞧!
<item> name="viewInflaterClass">androidx.appcompat.app.AppCompatViewInflater</item>
目前我正在更新我的项目以支持 AndroidX。
我已将所有库重构为新的 androidx
- 库。
尽管如此,仍然有一些依赖项,例如 com.wdullaer:materialdatetimepicker
,它们不会被更新,并且在 UI.
如何强制这些按钮使用新的 material 库? 我启用了选项
android.useAndroidX=true
android.enableJetifier=true
但如前所述,它不会影响这些库。
答案可以这么简单:
Material Components replaces all instances of Button with an instance of MaterialButton when using one of its regular themes: https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#material-components-themes The default version of MaterialButton uses colorPrimary as the background color. Because Material Components replaces the View replacer with their own implementation there is not much I can do to fix this from this library.
There are two workarounds:
Use one of the bridge themes, which do not replace the View Inflater Overwrite the View inflater again in your application theme by adding the following statement in your application theme: androidx.appcompat.app.AppCompatViewInflater You will then need to explicitly use MaterialButton in your application rather than Button
所以您基本上要做的就是将此行添加到您的应用程序主题中。然后,Material 组件将不再被替换。瞧!
<item> name="viewInflaterClass">androidx.appcompat.app.AppCompatViewInflater</item>