zoukankan      html  css  js  c++  java
  • Android XML资源文件中@、@android、@、?、@+的含义与区别

    1、@[<package_name>:][<resource_type>/]<resource_name>和 @+[<package_name>:][<resource_type>/]<resource_name>, @android:id 
    简单的概括就是:
    @[<resource_type/],resource_name>表示引用本应用中类型为reource_type的叫resource_name的资源。
    @[<package_name>:][<resource_type/],resource_name>表示引用packgage_name这个包中类型为reource_type的叫resource_name的资源。这里的包一般就是framework中的android。
    @+[<resource_type/],resource_name>表示新增加到本应用中类型为reource_type的叫resource_name的资源,通过aapt会自动生成一个整型的ID和它对应。
    @+[<package_name>:][<resource_type/],resource_name>表示新增加到package_name的包中类型为reource_type的叫resource_name的资源,通过aapt会自动生成一个整型的ID和它对应。 
    例:
    android:text="@string/hello" //引用string类中叫hello的资源
    android:textColor="@android:color/opaque_red" //引用系统资源
    android:id="@+id/my_button" //在R文件的id静态内部类中添加一个名为button的常量,该常量就是该资源的标识符;如果标示符(包括系统资源)已经存在则表示引用该标示符
    要了解更详细的信息可参看SDK文档/docs/guide/topics/ui/declaring-layout.html
     
    补充:
    要了解更详细的信息可参看SDK文档/docs/reference/android/view/View.html
    View IDs need not be unique throughout the tree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching.
     
    Tags
    Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.
     
     
     
    2、?[<package_name>:][<resource_type>/]<resource_name>
    简单的概括就是:
    ?<package_name>:] [<resource_type/],resource_name>表示使用当前应用使用的theme中的packgage_name这个包中类型为 reource_type的叫resource_name的资源。 
    要了解更详细的信息可参看SDK文档/docs/guide/topics/resources/accessing-resources.html
    例:
    <ProgressBar
            android:id="@+id/firstProgressBar"
            style="?android:progressBarStyleHorizontal"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:visibility="gone" />
    补充:@与?的区别
    ?引用主题属性[使用这个标记的前提是提供的资源名必须在主题属性中找到,因为资源工具认为该资源属性是被期望得到的,您不需要明确的指出它的类型也就是不需要写全在哪个文件中,即?android:attr/android:textDisabledColor]
    主题属性(名词解释):在android-sdkplatformsandroid-16data esvalues的attrs.xml文件中定义了Android系统的属性。同样,Android系统也为Theme定义了很多属性(可以看看attrs.xml文件),其中每个主题属性的名称都一一对应values目录下的themes.xml文件。当要用到主题属性的时候,就不需要特别指定android:attr/,可以直接在?后面加上属性名。
     
     
     
    3、@*[<package_name>:][<resource_type>/]<resource_name>  
    简单的概括就是:
    *[<package_name>:] [<resource_type/],resource_name>表示引用packgage_name这个包中类型为 reource_type的叫resource_name的资源。这里引用的一般是framework未公开的资源,即:android框架的内部资源。代码中对应的引用是com.android.internal.R.xx.xxx 。 
    区别:
    @*代表引用系统的非public资源,格式:@*android:type/name,系统资源定义分public和非public。public的声明在:<sdk_path>platformsandroid-8data esvaluespublic.xml
    @*android:type/name:可以调用系统定义的所有资源
    @android:type/name:只能够调用publi属性的资源。
    注意:没在public.xml中声明的资源,都不是公开的接口或者资源,是google不推荐使用的。Android XML资源文件中@、@android、@、?、@+的含义与区别.note





  • 相关阅读:
    单调栈问题解析
    Linux进程状态切换
    Shell编程小例子
    Linux之shell编程
    树的遍历框架
    你真的会求1-100有多少个素数吗
    java实现LRU算法
    从上到下打印二叉树 III
    从上到下打印二叉树I
    模拟盘电路板调试过程中出现的问题
  • 原文地址:https://www.cnblogs.com/linux007/p/5783105.html
Copyright © 2011-2022 走看看