color-在framwork中添加属性变量

1.今天在修改framwork中的代码的时候,需要把自己在代码中写的一个#ffffff,变成在xml中引用的变量。具体操作方法如下

1)在

frameworks/base/core/res/res/values

文件夹下的funui_colors.xml 中,设定color值

</resource>
    <color name="oos_power_off_text_color_off_funui">#4cffffff</color>
    <color name="oos_power_off_text_color_on_funui">#603cffef</color>
</resources>

2)直接在xml中引用

frameworks/base/core/res/res/layout

下的oos_global_actions_normal.xml 引用

<TextView
            android:layout_width="70dp"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textSize="14sp"
            android:textColor="@color/oos_power_off_text_color_off_funui"
            android:fadingEdge="none"
            android:layout_below="@+id/oos_apmode"
            android:layout_toLeftOf="@+id/oos_empty"
            android:paddingTop="15dp"
            android:gravity="center"
            android:text="@string/global_actions_toggle_airplane_mode"
            android:id="@+android:id/oos_apmode_title"/>

这些都是没有任何问题的

接下来,当我尝试在代码中使用的时候

import com.android.internal.R;

mViewOnTextColor = mContext.getResources().getColor(R.color.oos_power_off_text_color_off_funui);
mViewOffTextColor = mContext.getResources().getColor(R.color.oos_power_off_text_color_on_funui);

却一直提示说,找不到资源,后来才知道,如果你在framwork中添加了一个变量,而在其他路径下需要使用的时候,这时候你必须要进行注册

注册方法如下

frameworks/base/core/res/res/values

下文件 symbols.xml

<resource>
    <java-symbol type="color" name="oos_power_off_text_color_off_funui" />
    <java-symbol type="color" name="oos_power_off_text_color_on_funui" />
</resources>

这时候就可以了。

顺便有两点要注意下

1)就是这个关于R资源的介绍

我们知道,如果在eclipse下创建项目,我们设置的变量会自动在gen目录下的R.java文件中创建id。其实,在源码下,也有一个地方专门创建R文件,它的目录为

out/target/common/R

它下面的文件夹就是各个模块下的R文件。而我们的framwork下的文件,就是在

out/target/common/R/com/android/internal 

2)今天虽然成功增加了symbol,但是,编译的时候还是一直报错。后来才发现,有时候你更改了framework,最好是吧这个文件下的几个模块都编译一下

framework  SystemUI   android.policy

原文地址:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_symbol_150401185.html