android:icon ="@ drawable/my_icon"之间的区别和android:icon =“"?my_icon“? [英] Difference between android:icon="@drawable/my_icon" and android:icon="?my_icon"?

查看:62
本文介绍了android:icon ="@ drawable/my_icon"之间的区别和android:icon =“"?my_icon“?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常将xml中的drawable设置为 android:icon ="@ drawable/my_icon" 但是在某些项目中,我看到了代码 android:icon =?my_icon" .

I usually set drawable in xml as android:icon="@drawable/my_icon" But in some projects I see the code android:icon="?my_icon".

android:icon ="@ drawable/my_icon" android:icon =?my_icon" 有什么区别?

推荐答案

指向该文档并从中引用答案:

Pointing to this document and referencing the answer from there: Applying styles and themes

就像样式一样,主题也在XML元素中声明,并且以相同的方式引用.区别在于,您可以通过Android清单中的和元素将主题添加到整个应用程序或活动中-主题不能应用于单个视图.

Just like styles, themes are also declared in XML elements, and are referenced in the same manner. The difference is that you add a theme to an entire application or activity, via the and elements in the Android Manifest — themes cannot be applied to individual Views.

让我们以链接上定义的主题的声明为例:

Lets take an example declaration of a theme defined on the link:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="CustomTheme">  
    <item name="windowBackground">@drawable/screen_background_white</item>
    <item name="panelForegroundColor">#FF000000</item>
    <item name="panelBackgroundColor">#FFFFFFFF</item>      
    <item name="panelTextColor">?panelForegroundColor</item>
    <item name="panelTextSize">14</item>
    <item name="menuItemTextColor">?panelTextColor</item>
    <item name="menuItemTextSize">?panelTextSize</item>
  </style>
</resources>

请注意使用符号(@)和问号(?)来引用资源.符号-表示我们正在引用先前在其他位置定义的资源(可能来自该项目或Android框架).(例如,panelTextColor使用分配给panelForegroundColor的相同颜色,预先定义.)此技术只能在XML资源中使用.

Notice the use of the at-symbol (@) and the question-mark (?) to reference resources. The at-symbol indicates that we're referencing a resource previously defined elsewhere (which may be from this project or from the Android framework). (E.g., panelTextColor uses the same color assigned to panelForegroundColor, defined beforehand.) This technique can be used only in XML resources.

问号表示我们正在引用当前加载的主题中的资源值.这是通过引用特定名称的名称值来完成的.

The question-mark indicates that we're referencing a resource value in the currently loaded theme. This is done by referring to a specific by its name value.

因此,如果您看到 menuItemTextColor 指向另一个项目 panelTextColor ,则该项目的值再次带有问号.为什么?因为我们再次从当前加载的 customTheme 中引用资源值.

So, if you see that menuItemTextColor point to another item panelTextColor which again has question mark in front of its value. Why? Because we are again referencing a resource value from the currently loaded customTheme.

类似地,尽管您没有提到任何代码,但是当前加载的主题可能具有名为 my_icon item ,其值引用了指向项目.

Similarly although you haven't mentioned any code but its possible that the currently loaded theme has item called my_icon whose value references a resource value pointing to some drawable in the project.

希望这可以使您感到一清二楚.

Hope this clears you a bit.

这篇关于android:icon ="@ drawable/my_icon"之间的区别和android:icon =“"?my_icon“?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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