码迷,mamicode.com
首页 > 移动开发 > 详细

Android学习:资源管理

时间:2015-02-14 12:22:50      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:android   资源管理   

1:概括地讲,android的资源是指非代码部分,比如图片,MP3,字符串,xml文件等等


2:在一个android工程中,和src源文件并列的有两个文件夹,分别叫做res和assets,这两个文件都是来保存资源文件的。
     不同点:
(1)res的资源可以通过R资源类进行访问。这种方式在android中比较常用。
res包含子文件夹,对资源进行分类:
anim(xml动画文件),drawable(图片),layout(布局文件),menu(菜单),raw(二进制文件)values(常量值),xml(xml文件)

(2)assets中保存的一般是原始文件,例如:MP3文件,android程序不能直接通过R资源类访问。必须通过AssertManager类以二进制的形式读取。


3:res资源获取方式
(1)代码中:context的getResources()方法获得Resources对象,该对象提供了获得各种类型资源的方法。
(2)其他资源中引用资源
@[包名称:]资源类型/资源名称
R.资源类型.资源名称

xml中配置背景颜色
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity"
    android:background="@color/bg_color" >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" 
        android:textColor="@color/text_color"/>
    </RelativeLayout>


java中换背景颜色

this.getWindow().setBackgroundDrawableResource(R.color.bg_color);


技术分享

Android学习:资源管理

标签:android   资源管理   

原文地址:http://blog.csdn.net/u013628152/article/details/43816463

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!