androidx - 我应该如何将我的 AppTheme 样式转换为 Material 组件
问题描述
//这是我当前应用程序的 AppTheme。我应该如何将我的 AppTheme 迁移到 Material Components?我已将我的代码迁移到 AndroidX。
<style name="AppBaseTheme" parent="@android:style/Theme.Light">
<item name="android:windowActionBar">true</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:actionBarSize">@dimen/actionbar_height</item>
<item name="actionBarSize">@dimen/actionbar_height</item>
</style>
<!-- Base application theme. -->
<style name="AppThemeMenu" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowActionBar">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
解决方案
为了使用材料组件,首先在你的gradel文件中实现材料库:
implementation 'com.google.android.material:material:1.1.0'
然后,进入 style.xml 并将父级更改为以下材料父级之一:
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
有关更多信息,您可以查看此页面。
例如:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
希望这可以帮助!:)
推荐阅读
- .net - .Net 应用程序的 Windows 安装程序包生成器,提供其他软件下载
- c# - 将 XML 字符串 API 响应转换为键值对象 C#
- python - 使用基于两列的 if 条件更新数据框
- nim-lang - 如何在 Nim 中编写异步代码以由计时器定期调用?
- react-native - 如何在axios文件中调用useNavigation
- javascript - 无法通过 Nodejs 中的用户池返回的令牌访问身份池
- algorithm - T(n) = T(3n/4) + 2T(n/2) + n 的复杂度是多少?
- python-3.x - 在 scrapyd 中,如何通过 schedule api 传递 FEED_URI 值
- kubernetes - 无法让 Pod 绑定 minikube 中的本地存储。“节点未找到可用的持久卷”,“等待创建第一个消费者”
- python - 我们如何访问嵌入在 ul 和 li 标签中的锚标签链接,以使用 selenium 和 python 打开与该标签关联的链接