我创建了一个自定义主题,考虑了以下自定义属性:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="GlideColour" format="color"/>
<attr name="BackgroundColour" format="reference|color"/>
<attr name="SuggestionColour" format="color"/>
<attr name="KeyBackgroundColour" format="color"/>
<attr name="KeyBorderColour" format="color"/>
<attr name="SpaceBackgroundColour" format="color"/>
<attr name="SpaceTextColour" format="color"/>
<attr name="TextColour" format="color"/>
<attr name="BackEnterColour" format="color"/>
<attr name="PopUpDrawerColour" format="color"/>
<attr name="DrawerSelectColour" format="color"/>
<attr name="UtilityTextColour" format="color"/>
<attr name="KeyboardBackground" format="reference"/>
<attr name="KeyStyle" format="reference"/>
<attr name="SpaceStyle" format="reference"/>
<attr name="UtilityStyle" format="reference"/>
<attr name="EnterStyle" format="reference"/>
<attr name="BackStyle" format="reference"/>
<attr name="KeyboardStyle" format="reference"/>
<attr name="CapsStyle" format="reference"/>
<attr name="DrawerButtonStyle" format="reference"/>
</resources>
这是我制作的主题:
<style name="Standard" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="KeyboardBackground">@color/standard_background_color</item>
<item name="GlideColour">@color/standard_glide_color</item>
<item name="BackgroundColour">@color/standard_background_color</item>
<item name="SuggestionColour">@color/standard_suggestion_color</item>
<item name="SpaceBackgroundColour">@color/standard_space_background_color</item>
<item name="SpaceTextColour">@color/standard_space_text_color</item>
<item name="TextColour">@color/standard_text_color</item>
<item name="BackEnterColour">@color/standard_back_space_color</item>
<item name="UtilityTextColour">@color/standard_utility_color</item>
<item name="KeyStyle">@style/standard_key_button</item>
<item name="SpaceStyle">@style/standard_space_button</item>
<item name="UtilityStyle">@style/standard_utility_style</item>
<item name="EnterStyle">@style/standard_enter_style</item>
<item name="BackStyle">@style/standard_back_style</item>
<item name="KeyboardStyle">@style/standard_keyboard_style</item>
<item name="CapsStyle">@style/standard_caps_style</item>
<item name="DrawerButtonStyle">@style/standard_drawer_button_style</item>
</style>
但是,当从该主题应用自定义样式属性时,例如不会将其添加到视图中 :
<com.nisarg.nboard.SwipeLayout android:layout_width="match_parent"
android:layout_height="@dimen/keyboard_height"
style="?KeyboardStyle"
android:id="@+id/Rel"
xmlns:android="http://schemas.android.com/apk/res/android">
应该在哪里给我这个:
那是指引用样式根本没有添加到元素中。我不知道为什么这不起作用。这是什么问题?
这是所引用的样式
<style name="standard_keyboard_style" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">@color/standard_background_color</item>
</style>
我发现的问题是在引用中,我不能使用“ attr / ,否则会引发错误。
答案 0 :(得分:0)
尝试将属性声明为可样式化
赞:
testImplementation
更新
您可以对多个视图使用相同的自定义属性
赞:
<declare-styleable name="SwipeLayout">
<attr name="GlideColour" format="color"/>
<!-- other attributes go here-->
</declare-styleable>