主要存在于res/value文件夹中

定义:

dimen.xml:主要用于设置像素默认值

<resources>

res/values/dimens.xml

<dimen name="sp_12">12sp</dimen>
<dimen name="sp_13">13sp</dimen>

<dimen name="dip_40">40dip</dimen>
 <dimen name="dip_45">45dip</dimen>

</resources>

代码使用:

int width=getContext().getResources().getDimension(R.dimen.tab_width);

xml文件使用:

android:layout_width="@dimen/tab_width"

color.xml设置颜色

<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="drawable" name="main_background">#FFE7E7E7</item>
<item type="drawable" name="newslist_item_background">#FFE7E7E7</item>
<item type="color" name="white">#FFFFFFFF</item>
<item type="color" name="category_title_normal_background">#FFADB2AD</item>
<item type="color" name="gold">#b89766</item>
<item type="color" name="transparent">#000000</item>
<item type="color" name="textcolor">#FFFFFF</item>
<item type="color" name="bgcolor">#000000</item>
</resources>

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="contents_text">#ff000000</color>
<color name="encode_view">#ffffffff</color>
<color name="possible_result_points">#c0ffff00</color>
<color name="result_points">#c000ff00</color>
<color name="result_text">#ffffffff</color>
<color name="result_view">#b0000000</color>
<color name="share_text">#ff000000</color>
<color name="status_view">#50000000</color>
<color name="status_text">#ffffffff</color>
<color name="transparent">#00000000</color>
<color name="viewfinder_frame">#ff000000</color>
<color name="viewfinder_laser">#ffff0000</color>
<color name="viewfinder_mask">#60000000</color>
<color name="red">#ffff0000</color>
<color name="blue">#ff3590c4</color>
<color name="green">#7700ff00</color>
<color name="yellow">#ffff7000</color>
<color name="screen_background_white">#00ffffff</color>
<color name="translucent_background">#00000000</color>
<color name="white_background">#00ffffff</color>
<color name="gray_background">#fff7f7f7</color>
<color name="solid_red">#ffff0000</color>
<color name="solid_while">#ff888888</color>
<color name="solid_saffron">#ffff6414</color>
<color name="solid_blue">#ff0000ff</color>
<color name="solid_green">#ff00ff00</color>
<color name="solid_yellow">#ffffff00</color>
<color name="saffron">#ffffa649</color>
<color name="titlebackgroundcolor">#fffe8625</color>
<color name="listitem_divide">#ffd4d3d3</color>
<color name="gray">#ff666664</color>
<color name="deep_gray">#ff555555</color>
<color name="light_gray">#ff757575</color>
<color name="btn_focused_color_yellow">#fffdfdfd</color>
<color name="btn_pressed_color_light">#fffdfdfd</color>
<color name="btn_default_color_light">#ffff5f11</color>
<color name="rounded_container_border">#ffb7babb</color>
<color name="base_start_color_default">#ffffffff</color>
<color name="base_end_color_default">#ffffffff</color>
<color name="base_start_color_pressed">#ffff7a13</color>
<color name="base_center_color_pressed">#ffff8c2f</color>
<color name="base_end_color_pressed">#ffffa254</color>
<color name="text_color_default">#ff000000</color>
<color name="text_color_pressed">#ffffffff</color>
</resources>

调用color标签:android:background="@color/red" @color/是调用res/下的匹配的color标签

也可以将color标签嵌入到selector的item标签中使用

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="@color/red"/>
<item android:color="@color/green" />
</selector>

代码设置color方法:

testview.setTextColor(Color.parseColor("FFFFFF"));

testview.setTextColor(Color.GRAY);

tv.setTextColor(Color.rgb(255, 255, 255));

testview.setTextColor(getContext().getResources().getColor(R.color.my_color));

array.xml

<resources>
    <declare-styleable name="DragSort">
        <attr name="collapsed_height" format="dimension" />
        <attr name="drag_scroll_start" format="float" />
        <attr name="max_drag_scroll_speed" format="float" />
        <attr name="float_background_color" format="color" />
        <attr name="remove_mode">
            <enum name="clickRemove" value="0" />
            <enum name="flingRemove" value="1" />
        </attr>
        <attr name="track_drag_sort" format="boolean" />
        <attr name="float_alpha" format="float" />
        <attr name="slide_shuffle_speed" format="float" />
        <attr name="remove_animation_duration" format="integer" />
        <attr name="drop_animation_duration" format="integer" />
        <attr name="drag_enabled" format="boolean" />
        <attr name="sort_enabled" format="boolean" />
        <attr name="remove_enabled" format="boolean" />
        <attr name="drag_start_mode">
            <enum name="onDown" value="0" />
            <enum name="onMove" value="1" />
            <enum name="onLongPress" value="2" />
        </attr>
        <attr name="drag_handle_id" format="integer" />
        <attr name="fling_handle_id" format="integer" />
        <attr name="click_remove_id" format="integer" />
        <attr name="use_default_controller" format="boolean" />
    </declare-styleable>

</resources>

代码使用:

TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.DragSort, 0, 0);

mItemHeight = Math.max(1, array.getDimensionPixelSize(R.styleable.DragSortListView_collapsed_height, 1));

mTrackDragSort = array.getBoolean( R.styleable.DragSortListView_track_drag_sort, false);

xml使用:

<ListPreference
     android:title="@string/page_animation"
     android:defaultValue="@string/default_page_animation"
     android:entries="@array/page_animation_labels"
     android:entryValues="@array/page_animations"
     android:key="pageAnimation"
     />

strings.xml:主要设置文本

<resources>

<string name="button_confirm">确定</string>     
 <string name="button_cancel">取消</string>

<string-array name="page_animations">
  <item>100</item>
  <item>0</item>
  <item>1</item>
  <item>2</item>
  <item>3</item>
 </string-array>

</resources>

代码使用:

testview.setText(getString(R.string.button_confirm));

xml使用:

android:text="@string/button_confirm"

风格style与主题theme区别:

1:style主要用于View,theme主要用于Activity以及Application

2、style主要用于设置View的属性,theme主要用设置Activity的样式如是:否全屏

3、style与theme都是以<style><item>文本</item></style>创建,只是item的内容不一样

style定义:

style.xml文件

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="TitleStyle">

  <item name="android:textSize">18sp</item>

  <item name="android:textColor">#ec9237</item>

</style>

<style name="Title" parent="@style/TitleStyle"> (继承TitleStyle属性)

  <item name="android:textSize">5sp</item>

</style>

</resources>

代码使用:

xml使用:

<EditText android:layout_height="wrap_content"

android:text="EditText"

style="@style/Title"

android:layout_width="fill_parent"

android:id="@+id/editText1" />

-----------------------------------------------

theme:

style.xml

1.<?xml version="1.0" encoding="utf-8"?>

<resources>

  <style name="theme1">

    <item name="android:windowNoTitle">true</item>

    <item name="android:windowFullscreen">?android:windowNoTitle</item>

  </style>

  <style name="theme2.a">

    <item name="android:windowNoTitle">true</item>

    <item name="android:windowFullscreen">?android:windowNoTitle</item>

  </style>

</resources>

代码使用:

注意:setTheme应该在setContentView之前调用。

setTeme(R.theme.theme1);/setTeme(R.style.theme1)

setContentView(R.layout.main);

xml使用主题:

<application

  android:icon="@drawable/icon" android:label="@string/app_name"

  android:theme="@style/theme1">

  <activity

    android:name=".MessageShowActivity" android:label="@string/app_name"

    android:windowSoftInputMode="adjustPan" android:screenOrientation="portrait"

    android:theme="@style/theme2">

  </activity>

</application>

---------------------------------

android的selector是在drawable/xxx.xml中创建的:

selector:主要用设置view点击选中显示效果

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
  android:color="hex_color"
  android:state_pressed=["true" | "false"]
  android:state_focused=["true" | "false"]
  android:state_selected=["true" | "false"]
  android:state_checkable=["true" | "false"]
  android:state_checked=["true" | "false"]
  android:state_enabled=["true" | "false"]
  android:state_window_focused=["true" | "false"] />
</selector> android:drawable 放一个drawable资源
android:state_pressed 是否按下,如一个按钮触摸或者点击。
android:state_focused 是否取得焦点,比如用户选择了一个文本框。
android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性
android:state_selected 被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。
android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
android:state_checked 被checked了,如:一个RadioButton可以被check了。
android:state_enabled 能够接受触摸或者点击事件
android:state_activated 被激活(这个麻烦举个例子,不是特明白)
android:state_window_focused 应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了
------- <selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:state_window_focused="false" android:drawable="@drawable/pic1" /><!-- 没有焦点时的背景图片-->
  <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/pic2" /><!-- 非触摸模式下获得焦点并单击时的背景图片-->
  <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pic3" /><!-- 触摸模式下单击时的背景图片-->
  <item android:state_selected="true" android:drawable="@drawable/pic4" /><!--选中时的图片背景-->
  <item android:state_focused="true" android:drawable="@drawable/pic5" /><!--获得焦点时的图片背景-->
 </selector>

在xml中使用示例:

res/color/button_text.xml

<?xml version="1.0" encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
    <item
      android:state_pressed="true"
        android:color="#ffff0000"/><!-- pressed -->
   <item
      android:state_focused="true"
        android:color="#ff0000ff"/><!-- focused -->
   <itemandroid:color="#ff000000"/><!-- default -->
</selector>
<Button
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
   android:text="@string/button_text"
   android:textColor="@color/button_text"/> 参考:http://www.cnblogs.com/navy-wang/p/3314034.html

android 中resources管理的更多相关文章

  1. Android中使用SQLiteOpenHelper管理SD卡中的数据库

    使用Android中自带的SQLiteOpenHelper可以完成数据库的创建与管理,但有两点局限: (1)数据库创建在内存卡中,大小受限,创建位置位于/data/data/应用程序名/databas ...

  2. 在Android中查看和管理sqlite数据库

    在Android中可以使用Eclipse插件DDMS来查看,也可以使用Android工具包中的adb工具来查看.android项目中的sqlite数据库位于/data/data/项目包/databas ...

  3. 【转】Android中的内存管理--不错不错,避免使用枚举类型

    原文网址:http://android-performance.com/android/2014/02/17/android-manage-memory.html 本文内容翻译自:http://dev ...

  4. android中的常用布局管理器(三)

    接上篇博客 (5)TableLayout     表格布局管理器 在android中,线性布局和表格布局用的是最多的. 在很多的输出操作中,往往会使用表格的形式对显示的数据进行排版,tablelayo ...

  5. android中常用的布局管理器

    Android中的几种常用的布局,主要介绍内容有: View视图 RelativeLayout    相对布局管理器 LinearLayout     线性布局管理器 FrameLayout     ...

  6. Android中的内存管理机制以及正确的使用方式

    概述 从操作系统的角度来说,内存就是一块数据存储区域,属于可被操作系统调度的资源.现代多任务(进程)的操作系统中,内存管理尤为重要,操作系统需要为每一个进程合理的分配内存资源,所以可以从两方面来理解操 ...

  7. Android中ListView实现图文并列并且自定义分割线(完善仿微信APP)

    昨天的(今天凌晨)的博文<Android中Fragment和ViewPager那点事儿>中,我们通过使用Fragment和ViewPager模仿实现了微信的布局框架.今天我们来通过使用Li ...

  8. Android 中常见控件的介绍和使用

    1 TextView文本框 1.1 TextView类的结构 TextView 是用于显示字符串的组件,对于用户来说就是屏幕中一块用于显示文本的区域.TextView类的层次关系如下: java.la ...

  9. android 进程/线程管理(二)----关于线程的迷思

    一:进程和线程的由来 进程是计算机科技发展的过程的产物. 最早计算机发明出来,是为了解决数学计算而发明的.每解决一个问题,就要打纸带,也就是打点. 后来人们发现可以批量的设置命令,由计算机读取这些命令 ...

随机推荐

  1. Sensor(ACCELEROMETER)

    package com.example.sensor01; import java.util.List; import android.hardware.Sensor; import android. ...

  2. 人人都是 DBA(VIII)SQL Server 页存储结构

    当在 SQL Server 数据库中创建一张表时,会在多张系统基础表中插入所创建表的信息,用于管理该表.通过目录视图 sys.tables, sys.columns, sys.indexes 可以查看 ...

  3. Angular Module声明和获取重载

    module是angular中重要的模块组织方式,它提供了将一组内聚的业务组件(controller.service.filter.directive…)封装在一起的能力.这样做可以将代码按照业务领域 ...

  4. VS2012下配置MPI

    并行处理结课实验,要用到MPI编程,我的电脑和VS2012都是64位的,以为MPICH也得是64位才行,结果饶了很大的弯——配置正确,添加引用之后,仍然无法识别MPI函数. 后来换了个32位的MPIC ...

  5. css position全解析

    1.position:static 所有的元素的默认定位都是position:static,这意味着元素没有被定位,而且在文档中出现在它应该在的位置. 2.position:relative 如果设定 ...

  6. BIT祝威博客汇总(Blog Index)

    +BIT祝威+悄悄在此留下版了个权的信息说: 关于硬件(Hardware) <穿越计算机的迷雾>笔记 继电器是如何成为CPU的(1) 继电器是如何成为CPU的(2) 关于操作系统(Oper ...

  7. Visual Studio 2010 实用功能:使用web.config发布文件替换功能

    当建立ASP.NET Web应用程序项目后,默认除了生成web.config外,还生成了web.debug.config与Web.Release.config.顾名思义,根据它们的命名我可以推测到他们 ...

  8. struts2学习笔记之十三:自定义过滤器

    Struts2的拦截器 1.Struts2的拦截器只能拦截Action,拦截器是AOP的一种思路,可以使我们的系统架构 更松散(耦合度低),可以插拔,容易互换,代码不改变的情况下很容易满足客户需求 其 ...

  9. 函数柯理化以及利用柯理化实现bind方法

    1.函数柯理化 把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数而且返回结果的新函数的技术. 柯理化函数思想:一个js预先处理的思想:利用函数执行可以形 ...

  10. salesforce 零基础学习(二十四)解析csv格式内容

    salesforce中支持对csv格式的内容批量导入,可以使用dataloader,然而有些情况下,当用户没有相关权限使用dataloader导入情况下,就的需要使用VF和apex代码来搞定. 基本想 ...