android - 如何通过更改android中的主题来更改背景颜色?
问题描述
当我在android中更改主题时,我想更改背景颜色。有没有办法在 XML 中设置背景,比如
android:background="@styles/colorAccent"
因此,当我更改主题时,背景颜色会自动更改为相应主题的 colorAccent。任何替代方法也会有所帮助。
解决方案
样本布局
<FrameLayout
style="@style/colorAccentStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content/>
样式.xml
<resources>
<style name="colorAccentStyle">
<item name="android:background">?colorAccent</item>
</style>
更简单的解决方案
<FrameLayout
android:background="?colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
推荐阅读
- sql - 实现包含所有效果的 SQL 查询问题
- php - 为什么总是“为 foreach 提供的参数无效”
- objective-c - 在Objective C中使用NSURLConnection解析json时获取服务器错误消息
- wordpress - 想在worpress中修剪中文字
- vba - 使用 VBA 验证多个单元格数据
- c++ - Reading data from .txt file and saving into multiple vectors using c++
- php - 将数据表单视图传递给控制器 guzzle Laravel 5
- windows - 用于从网络驱动器中删除文件的批处理文件命令
- jquery - 将禁用属性添加到无法在开发人员选项中修改的选择框
- dji-sdk - 如何在没有遥控器(或关闭遥控器)的情况下获取 DJI Onboard SDK 控制权限