造型自定义视图自定义、视图、造型

2023-09-04 11:54:54 作者:一见终情。

我已经在我的Andr​​oid项目的几个自定义的意见,我已经添加了相关的细节到attrs.xml文件。现在,我可以通过XML实现我的目标。这工作得很好。

我如何风格这些元素?当我尝试使用我的自定义属性在styles.xml中得到一个错误没有资源的发现,匹配给定的名字:

有关使用自定义视图中的常规XML研究与开发我用的xmlns:程序=htt​​p://schemas.android.com/apk/res/bla.bla.bla。什么是正确的方式使用?

这就是我的风格看起来像目前

 <样式名称=Journey_DaySelect_Sunday>
    <项目名称=应用程序:onImage> @可绘制/ day_sunday_selected< /项目>
    <项目名称=应用程序:offImage> @可绘制/ day_sunday< /项目>
< /风格>
 
如何自定义Excel视图模式

解决方案

更​​深入的搜索后的谷歌,我放弃了发现它在其他地方回答,和偶然使用我的生成R的绝对空间尝试文件它的工作。愿这解决所有的问题。

用命名空间包含您的R档

 <样式名称=Journey_DaySelect_Sunday父=Journey_DaySelect>
    <项目名称=AppZappy.NIRailAndBus:onImage> @可绘制/ day_sunday_selected< /项目>
    <项目名称=AppZappy.NIRailAndBus:offImage> @可绘制/ day_sunday< /项目>
< /风格>
 

I have a few custom views in my Android project and I've added the relevant details to the attrs.xml file. And now I can implement my objects through XML. This works fine.

How do I style these elements? When I try to use my custom attributes in the styles.xml is get an error "No resource found that matches the given name:"

For using the custom views in normal xml developement I use xmlns:app="http://schemas.android.com/apk/res/bla.bla.bla". What is the correct for use in styles?

This is what my style looks like currently

<style name="Journey_DaySelect_Sunday">
    <item name="app:onImage">@drawable/day_sunday_selected</item>
    <item name="app:offImage">@drawable/day_sunday</item>
</style>

解决方案

After more intensive searching on Google I gave up finding it answered elsewhere, and by chance tried using the absolute namespace of my generated R file it worked. May this solve all your problems.

USE THE NAMESPACE CONTAINING YOUR R FILE

<style name="Journey_DaySelect_Sunday" parent="Journey_DaySelect">
    <item name="AppZappy.NIRailAndBus:onImage">@drawable/day_sunday_selected</item>
    <item name="AppZappy.NIRailAndBus:offImage">@drawable/day_sunday</item>
</style>