造型自定义视图 [英] Styling Custom Views

查看:114
本文介绍了造型自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的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< /项目>
< /风格>
 

解决方案

更​​深入的搜索后的谷歌,我放弃了发现它在其他地方回答,和偶然使用我的生成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>

这篇关于造型自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆