android系统资源之主题以及styleable、style关系

转载请注明出处:http://blog.csdn.net/droyon/article/details/22686967

1、在framework/base/core/res/res/values/attrs.xml文件中,定义了名称为theme的styleable,其中包含了几十项属性。styleable是一个集合化属性集,其作用是便于我们从style中取出相应的属性。

文件内容片段:

<declare-styleable name="Theme">
        <!-- ============== -->
        <!-- Generic styles -->
        <!-- ============== -->
        <eat-comment />

        <!-- Default color of foreground imagery. -->
        <attr name="colorForeground" format="color" />
        <!-- Default color of foreground imagery on an inverted background. -->
        <attr name="colorForegroundInverse" format="color" />
        <!-- Color that matches (as closely as possible) the window background. -->
        <attr name="colorBackground" format="color" />
        <!-- This is a hint for a solid color that can be used for caching
             rendered views.  This should be the color of the background when
             there is a solid background color; it should be null when the
             background is a texture or translucent.  When a device is able
             to use accelerated drawing (thus setting state_accelerated), the
             cache hint is ignored and always assumed to be transparent. -->
        <attr name="colorBackgroundCacheHint" format="color" />

        <!-- Default highlight color for items that are pressed. -->
        <attr name="colorPressedHighlight" format="color" />
        <!-- Default highlight color for items that are long-pressed. -->
        <attr name="colorLongPressedHighlight" format="color" />
        <!-- Default highlight color for items that are
             focused. (Focused meaning cursor-based selection.) -->
        <attr name="colorFocusedHighlight" format="color" />
        <!-- Default highlight color for items that are
             activated. (Activated meaning persistent selection.) -->
        <attr name="colorActivatedHighlight" format="color" />
这些styleable只能用于activity或者application中,因为只有activity或者application才能解析这些属性。

这个文件还定义了View以及ViewGroup能够解析的属性。

<declare-styleable name="View">
        <!-- Supply an identifier name for this view, to later retrieve it
             with {@link android.view.View#findViewById View.findViewById()} or
             {@link android.app.Activity#findViewById Activity.findViewById()}.
             This must be a
             resource reference; typically you set this using the
             <code>@+</code> syntax to create a new ID resources.
             For example: <code>android:id="@+id/my_id"</code> which
             allows you to later retrieve the view
             with <code>findViewById(R.id.my_id)</code>. -->
        <attr name="id" format="reference" />

        <!-- Supply a tag for this view containing a String, to be retrieved
             later with {@link android.view.View#getTag View.getTag()} or
             searched for with {@link android.view.View#findViewWithTag
             View.findViewWithTag()}.  It is generally preferable to use
             IDs (through the android:id attribute) instead of tags because
             they are faster and allow for compile-time type checking. -->
        <attr name="tag" format="string" />

        <!-- The initial horizontal scroll offset, in pixels.-->
        <attr name="scrollX" format="dimension" />
2、framework/base/core/res/res/values/attrs_manifest.xml文件中定义了AndroidManifest.xml文件才能使用的属性。

 <attr name="theme" format="reference" />

<attr name="permission" format="string" />
<attr name="launchMode">
        <!-- The default mode, which will usually create a new instance of
             the activity when it is started, though this behavior may change
             with the introduction of other options such as
             {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK
             Intent.FLAG_ACTIVITY_NEW_TASK}. -->
        <enum name="standard" value="0" />
        <!-- If, when starting the activity, there is already an
            instance of the same activity class in the foreground that is
            interacting with the user, then
            re-use that instance.  This existing instance will receive a call to
            {@link android.app.Activity#onNewIntent Activity.onNewIntent()} with
            the new Intent that is being started. -->
        <enum name="singleTop" value="1" />
        <!-- If, when starting the activity, there is already a task running
            that starts with this activity, then instead of starting a new
            instance the current task is brought to the front.  The existing
            instance will receive a call to {@link android.app.Activity#onNewIntent
            Activity.onNewIntent()}
            with the new Intent that is being started, and with the
            {@link android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT
            Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT} flag set.  This is a superset
            of the singleTop mode, where if there is already an instance
            of the activity being started at the top of the stack, it will
            receive the Intent as described there (without the
            FLAG_ACTIVITY_BROUGHT_TO_FRONT flag set).  See the
            <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
            Stack</a> document for more details about tasks.-->
        <enum name="singleTask" value="2" />
        <!-- Only allow one instance of this activity to ever be 
            running.  This activity gets a unique task with only itself running 
            in it; if it is ever launched again with the same Intent, then that 
            task will be brought forward and its 
            {@link android.app.Activity#onNewIntent Activity.onNewIntent()}
            method called.  If this 
            activity tries to start a new activity, that new activity will be 
            launched in a separate task.  See the
            <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
            Stack</a> document for more details about tasks.-->
        <enum name="singleInstance" value="3" />
    </attr>
3、framework/base/core/res/res/values/theme.xml文件中定义了style,这个是样式,也是theme属性所对应的。theme是个引用值,styleable与style之间的关系,可以这样描述,一、styleable定义了属性集合,style包含了实际的值。二、theme定义在android空间,因而必须Android:theme这样使用。style不是一个attr属性,因而无需使用android命名空间。


android系统资源之主题以及styleable、style关系,布布扣,bubuko.com

android系统资源之主题以及styleable、style关系

上一篇:Android 深入研究LBS(基于位置的服务)


下一篇:iOS定位原理和使用建议