Android 主题和样式属性差异 "android:xxxx" vs "xxxx"
Android theme and style attributes difference "android:xxxx" vs "xxxx"
我现在使用AppCompat Theme来设计UI。在设计这个 UI 样式时,我发现样式属性有些混乱。
部分项名,如果不是android:xxxx开头,编译会失败,找不到项名。
但其他一些,如果以android:xxxx开头,则不会应用该样式。
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:colorBackground">@android:color/white</item>
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<item name="autoCompleteTextViewStyle">@style/cursorColor</item>
<item name="editTextStyle">@style/textCursorColor</item>
</style>
<style name="MyToolbarPopupStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">@android:color/white</item>
<item name="android:textColor">@android:color/black</item>
<item name="searchViewStyle">@style/MySearchViewStyle</item>
</style>
<style name="textCursorColor" parent="Widget.AppCompat.EditText">
<item name="android:textCursorDrawable">@drawable/text_cursor</item>
</style>
例如:
在 appTheme 中:如果使用 android:editTextStyle,则不会应用 textCursorColor。所以我需要删除 "android:"
在 MyToolbarPopupStyle 中:如果使用 textColor,将出现编译错误,找不到与属性匹配的资源。在这种情况下,我需要添加 "android:"。
使用有什么规定吗?或者我需要尝试错误添加 "android:" 或不?
Is there any rules for using? Or i need to try and error to add "android:" or not?
attrs
和 styleable
属性是 Android SDK 的一部分,定义了所有这些值
在styleable
中,android:editTextStyle
是defined as the Default EditText style。
并且在 attrs
、it also says the same thing 中,但没有 android:
前缀
是否有效似乎是反复试验,除非您愿意深入研究为那些 views/themes/styles 定义的自定义属性的源代码。 (换句话说,android:
是在基础 SDK 中定义的)
中看到
项目名称 "android:" 是 android 特定的名称,而没有 android:是在您继承自的主题或样式中定义的自定义属性。
例如"searchViewStyle"是在"ThemeOverlay.AppCompat.Light"
中定义的自定义属性
我现在使用AppCompat Theme来设计UI。在设计这个 UI 样式时,我发现样式属性有些混乱。
部分项名,如果不是android:xxxx开头,编译会失败,找不到项名。
但其他一些,如果以android:xxxx开头,则不会应用该样式。
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:colorBackground">@android:color/white</item>
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<item name="autoCompleteTextViewStyle">@style/cursorColor</item>
<item name="editTextStyle">@style/textCursorColor</item>
</style>
<style name="MyToolbarPopupStyle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:colorBackground">@android:color/white</item>
<item name="android:textColor">@android:color/black</item>
<item name="searchViewStyle">@style/MySearchViewStyle</item>
</style>
<style name="textCursorColor" parent="Widget.AppCompat.EditText">
<item name="android:textCursorDrawable">@drawable/text_cursor</item>
</style>
例如:
在 appTheme 中:如果使用 android:editTextStyle,则不会应用 textCursorColor。所以我需要删除 "android:"
在 MyToolbarPopupStyle 中:如果使用 textColor,将出现编译错误,找不到与属性匹配的资源。在这种情况下,我需要添加 "android:"。
使用有什么规定吗?或者我需要尝试错误添加 "android:" 或不?
Is there any rules for using? Or i need to try and error to add "android:" or not?
attrs
和 styleable
属性是 Android SDK 的一部分,定义了所有这些值
在styleable
中,android:editTextStyle
是defined as the Default EditText style。
并且在 attrs
、it also says the same thing 中,但没有 android:
前缀
是否有效似乎是反复试验,除非您愿意深入研究为那些 views/themes/styles 定义的自定义属性的源代码。 (换句话说,android:
是在基础 SDK 中定义的)
项目名称 "android:" 是 android 特定的名称,而没有 android:是在您继承自的主题或样式中定义的自定义属性。
例如"searchViewStyle"是在"ThemeOverlay.AppCompat.Light"
中定义的自定义属性