android - What is the difference b/w app:theme & android:theme in Android Programming
问题描述
I have seen this that some people write
app:theme="@style/xyz"
& on the other hand some write
android:theme="@style/xyz"
What is the difference b/w these 2 codes?
解决方案
app
并且android
实际上是命名空间。packages
您可以像在 java
中一样考虑它们。android
命名空间包含来自默认视图的属性,其中 asapp
指的是来自应用程序命名空间的属性,例如来自自定义视图的属性。
因此,当您编写时android:theme
,它将使用主题属性,该属性是默认视图的一部分,例如 TextView(它是 Android 的一部分)。现在,当您使用app:theme
这意味着您正在谈论自定义主题属性而不是默认属性。当您构建扩展另一个视图的 CustomView 并且您还想更改theme
属性分配值的方式时,这可能很有用,例如,您可能想要构建自定义视图以向 TextView 添加阴影并且您想要阴影主题中提供的颜色。
AppCompat 库中的视图app:theme
用于制作自己的版本android:theme
以支持旧版本。
TLDR;Usingandroid:theme
使用 View 的默认主题功能,而app:theme
用于自定义视图中的自定义主题功能。如果您使用的是 AppCompatView 或自定义视图,app:theme
请在可用时使用,否则android:theme
.
如果我在 MaterialDesign/AppCompat 或任何其他自定义视图中使用android:theme
而不是会发生什么?app:theme
如果您这样做,所有视图中可用的视图属性将是可自定义的,但自定义视图添加的任何新属性都无法通过主题进行自定义。
推荐阅读
- vb.net - Visual Studio 2019 VB 窗体不再打开
- applescript - 如何在不阻止 Finder 的情况下监控文件夹内容
- assembly - 如何将存储在变量中的整数转换为浮点数,并将其存储在不同的变量(程序集)中?
- c++ - 访问类中的数组值,c ++
- c# - 计算在 IoT Core 上运行的控制台应用程序的系统 CPU 使用率
- java - 如何从网络接口获取 IP 配置
- sqlite - 未捕获的错误:打包应用后请手动安装sqlite3包错误
- python - 我对 MLP 模型做错了什么?
- java - memcache 不在多个节点上工作
- javascript - jQuery .submit() 在新选项卡中提交表单一次但不提交第二次