android 资源引用 自定义标题栏
http://blog.sina.com.cn/s/blog_72fad6270100x7k2.html
styles.xml放在res/values文件夹中
具体放在哪里,这要深入了解android中关于资源引用的部分
一般情况下(除values文件夹),res文件夹下的子文件夹都对应R.java中的一个内部类,类名就是该子文件夹的名字;
子文件夹下的资源项都对应内部类的一个int型的Field.
一、下面给出res下的文件结构图:
二、下面给出R.java,对应res文件结构,观察它的类名和类中的成员
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.lucus.librarysixth;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int bg=0x7f020000;
public static final int bg2=0x7f020001;
public static final int ic_launcher=0x7f020002;
}
public static final class id {
public static final int authorTV=0x7f070007;
public static final int cancleBtn=0x7f070011;
public static final int conRemindBtn=0x7f070001;
public static final int dayTV=0x7f07000d;
public static final int delRemindBtn=0x7f070002;
public static final int displayLV=0x7f070005;
public static final int label=0x7f07000e;
public static final int monthTV=0x7f07000c;
public static final int okBtn=0x7f070010;
public static final int pagesTV=0x7f07000a;
public static final int priceTV=0x7f070009;
public static final int publisherTV=0x7f070008;
public static final int returnBooksLV=0x7f070000;
public static final int searchBtn=0x7f070004;
public static final int setPropertyBtn=0x7f070006;
public static final int spinner1=0x7f07000f;
public static final int titleTV=0x7f070003;
public static final int yearTV=0x7f07000b;
}
public static final class layout {
public static final int alarm=0x7f030000;
public static final int alarm_vlist=0x7f030001;
public static final int main=0x7f030002;
public static final int main_title=0x7f030003;
public static final int main_vlist=0x7f030004;
public static final int property_set=0x7f030005;
public static final int single_set=0x7f030006;
}
public static final class raw {
public static final int music=0x7f040000;
}
public static final class string {
public static final int app_name=0x7f050001;
public static final int hello=0x7f050000;
}
public static final class style {
public static final int CustomWindowTitleBackground=0x7f060000;
public static final int test=0x7f060001;
}
}
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.lucus.librarysixth;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int bg=0x7f020000;
public static final int bg2=0x7f020001;
public static final int ic_launcher=0x7f020002;
}
public static final class id {
public static final int authorTV=0x7f070007;
public static final int cancleBtn=0x7f070011;
public static final int conRemindBtn=0x7f070001;
public static final int dayTV=0x7f07000d;
public static final int delRemindBtn=0x7f070002;
public static final int displayLV=0x7f070005;
public static final int label=0x7f07000e;
public static final int monthTV=0x7f07000c;
public static final int okBtn=0x7f070010;
public static final int pagesTV=0x7f07000a;
public static final int priceTV=0x7f070009;
public static final int publisherTV=0x7f070008;
public static final int returnBooksLV=0x7f070000;
public static final int searchBtn=0x7f070004;
public static final int setPropertyBtn=0x7f070006;
public static final int spinner1=0x7f07000f;
public static final int titleTV=0x7f070003;
public static final int yearTV=0x7f07000b;
}
public static final class layout {
public static final int alarm=0x7f030000;
public static final int alarm_vlist=0x7f030001;
public static final int main=0x7f030002;
public static final int main_title=0x7f030003;
public static final int main_vlist=0x7f030004;
public static final int property_set=0x7f030005;
public static final int single_set=0x7f030006;
}
public static final class raw {
public static final int music=0x7f040000;
}
public static final class string {
public static final int app_name=0x7f050001;
public static final int hello=0x7f050000;
}
public static final class style {
public static final int CustomWindowTitleBackground=0x7f060000;
public static final int test=0x7f060001;
}
}
三、总结
1、id类是在xml中定义的控件id
2、在java代码中使用资源
R.[R.java文件中的内部类]/[内部类中的int类型的Field]
如:R.string.app_name
3、在xml中使用资源
@<资源对应的内部类类名>/<资源项的名称>
如:@string/app_name