首页 > 解决方案 > 如何使用价值'?attr / actionButtonStyle制作'风格'

问题描述

[/storage/emulated/0/.sketchware/data/743/files/resource/layout/custom_action_item_layout.xml:2:错误:错误:找不到与给定名称匹配的资源(在“样式”中,值为“?attr/ actionButtonStyle')., , /storage/emulated/0/.sketchware/data/743/files/resource/menu/main_menu.xml:6: 错误:在包'com.my.中找不到属性'actionLayout'的资源标识符。 newproject9', , /storage/emulated/0/.sketchware/data/743/files/resource/menu/main_menu.xml:6: 错误:在包'com.my.newproject9'中找不到属性'showAsAction'的资源标识符, ]

标签: javaandroidxmlmobile

解决方案


可能您已经actionButtonStyle从某处引用了 attr,并且此属性未在您的 App 主题中设置。

假设您正在为您的应用程序使用材料主题,首先,为您的按钮创建一个主题。以下是一个示例,您可以根据需要对其进行自定义:

<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
    <item name="materialThemeOverlay">@style/ThemeOverlay.App.Button</item>
    <item name="android:textAppearance">@style/TextAppearance.App.Button</item>
    <item name="shapeAppearance">@style/ShapeAppearance.App.SmallComponent</item>
</style>

现在,在您的应用主题中,将此属性值设置为新主题:

<!--Your app theme might be different than the following, just put that attribute inside-->
<style name="Theme.App" parent="Theme.MaterialComponents.*">
    ...
    <item name="actionButtonStyle">@style/Widget.App.Button</item>
</style>

希望这可以帮助。


推荐阅读