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命名空间。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hailushijie

您的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值