android - 将 Theme.DeviceDefault 与 AppCompatActivity 一起使用
问题描述
我有一个AppCompatActivity
基于Theme.AppCompat
. 我想创建一个相同应用程序的风格,但它使用Theme.DeviceDefault
主题。当我更改主题时,我收到此错误:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
我考虑用 替换所有实例AppCompatActivity
,FragmentActivity
但这会导致很多功能中断。
有没有办法在使用的Theme.DeviceDefault
应用程序中使用主题AppCompatActivity
?
解决方案
我不知道,但您可能需要考虑以下事项;
随着新版本平台的发布,例如根据源代码引入了新组件,似乎 Theme.AppCompat 将正确处理以前不可用的不同组件/资源的样式,并设置重要的东西,例如视图充气器类 <item name="viewInflaterClass">android.support.v7.app.AppCompatViewInflater</item>
这就是它使用 V7 基本主题作为其父主题的原因:
<style name="Base.Theme.AppCompat" parent="Base.V7.Theme.AppCompat">
您的另一个选择(我没有测试过)是深入了解您想要使用的主题中的资源并将它们全部复制,这当然很痛苦。
<!-- The default theme for apps that target API level XX and higher. <p>The DeviceDefault themes are aliases for a specific device’s native look and feel. The DeviceDefault theme family and widget style family offer ways for you to target your app to a device’s native theme with all device customizations intact.</p> <p>For example, when you set your app's {@code targetSdkVersion} to XX or higher, this theme is applied to your application by default. As such, your app might appear with the {@link #Theme_Material Material} styles on one device, but with a different set of styles on another device. This is great if you want your app to fit with the device's native look and feel. If, however, you prefer to keep your UI style the same across all devices, you should apply a specific theme such as {@link #Theme_Material Material} or one of your own design. For more information, read <a href="http://android-developers.blogspot.com/20XX/XX/material-everywhere.html">Material Everywhere</a>.</p> <p>Styles used by the DeviceDefault theme are named using the convention Type.DeviceDefault.Etc (for example, {@code Widget.DeviceDefault.Button} and {@code TextAppearance.DeviceDefault.Widget.PopupMenu.Large}).</p> -->
推荐阅读
- php - 将远程图像添加到 PhpSpreadset 单元格
- flutter - 异常类型 Future(void) 不是 Future 的子类型
- c - AF_XDP: `BPF_MAP_TYPE_XSKMAP` 仅包含 `Operation not supported` 的条目
- django - 使用 JWT 身份验证登录后重定向
- excel - 将一张纸的最后一行相乘并放置到另一张纸上
- python - Socket编程使用python从不同系统上的软件接收TCP数据
- python-3.x - Google-Cloud-Scheduler 因 http 触发 Cloud Function 而失败
- python - 按字符串过滤给我空结果
- c# - 为什么 file.PostedFile 总是为空
- php - Laravel 6 - 联盟跟踪用户注册