http://developer.android.com/guide/topics/resources/more-resources.html

http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList

 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:主要用于设置颜色值

<resources>

  res/values/colors.xml

<color name="transparent">#00000000</color>
    <color name="pink">#ffff88ff</color>

<drawable name="transparent_background">#00000000</drawable>//

  1. res/values/filename.xml
    <boolname="screen_small">true</bool>//boolean
    <boolname="adjust_view_bounds">true</bool>
  2.  
  3. res/values/filename.xml
  1. <itemtype="id"name="id_name"/>
  1.  

</resources>

代码设置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));

Resources res =getResources();boolean screenIsSmall = res.getBoolean(R.bool.screen_small);

Resources res =getResources();int color = res.getColor(R.color.opaque_red);

Resources res =getResources();float fontSize = res.getDimension(R.dimen.font_size);

xml使用:

android:background="@color/transparent"

android:adjustViewBounds="@bool/adjust_view_bounds"

android:textSize="@dimen/font_size"

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

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点击选中显示效果

  1. <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>
  2.  
  3. 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 应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了
    -------
  4.  
  5. <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

  1. <?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>
  1. <Button
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
       android:text="@string/button_text"
       android:textColor="@color/button_text"/>
    --------------------------------

android resources使用总结的更多相关文章

  1. cocos2dx android resources.ap_ does not exist

    当我们在eclipse中打开cocos2dx自动创建的工程时,经常会出现错误: cocos2dx android resources.ap_ does not exist 这是因为android工程的 ...

  2. Andriod(3)——Understanding Android Resources

    Now, we will follow that introduction with an in-depth look at Android SDK fundamentals and cover re ...

  3. Illegal resource reference: @*android resources are private and not always present

    0:前言 在android开发中,当使用别人的代码的时候,在style.xml中有此种错误 1:解决方案 删除*星号

  4. android Resources 类的使用

    使用 R.<resource_type>.<resource_name> 获取的是资源的一个 id (int 类型), 但有时候我们需要获取资源本身,这时候我们可以通过 Res ...

  5. Android Resources

    Ref:Android开发最佳实践 Ref:Android高手速成--第一部分 个性化控件(View) Ref:Android高手速成--第二部分 工具库 Ref:Android高手速成--第三部分 ...

  6. Android Weekly Notes Issue #224

    Android Weekly Issue #224 September 25th, 2016 Android Weekly Issue #224 本期内容包括: Google Play的pre-lau ...

  7. [译]:Xamarin.Android开发入门——Hello,Android Multiscreen深入理解

    原文链接:Hello, Android Multiscreen_DeepDive. 译文链接:Xamarin.Android开发入门--Hello,Android Multiscreen深入理解. 本 ...

  8. [译]:Xamarin.Android开发入门——Hello,Android深入理解

    返回索引目录 原文链接:Hello, Android_DeepDive. 译文链接:Xamarin.Android开发入门--Hello,Android深入理解 本部分介绍利用Xamarin开发And ...

  9. Xamarin Mono For Android 4.6.07004 完整离线安装破解版(C#开发Android、IOS工具)

      Xamarin是由Miguel de Icaza成立的一家新的独立公司,目的是给Mono一个继续奋斗的机会.Mono for Android (原名:MonoDroid)可以让开发人员使用 Mic ...

随机推荐

  1. 如何向Openstack社区提交一个新项目

    前几天有个朋友问我:自己有一个idea不错的项目,也把基本的框架写好了,想贡献到Openstack社区,却不知道应该怎么做.正好之前我有过类似的经历,那么来分享一下我是如何向Openstack社区提交 ...

  2. Hadoop-2.6.0 + Zookeeper-3.4.6 + HBase-0.98.9-hadoop2环境搭建示例

    1    基本信息 1.1     软件信息 hadoop-2.6.0 zookeeper-3.4.6 hbase-0.98.9-hadoop2 (以下示例中使用的操作系统是Centos 6.5,请将 ...

  3. 源代码安装 MySQL 5.6.28

    本文内容 创建 MySQL 用户和组 解压 MySQL 源代码包 生成配置安装文件 编译和安装 MySQL 配置文件 创建 MySQL 授权表 MySQL 目录授权 启动 MySQL 验证 MySQL ...

  4. A Brief History of Scaling LinkedIn

    原文地址 LinkedIn started in 2003 with the goal of connecting to your network for better job opportuniti ...

  5. 转:VC解析XML文件-CMarkup的使用详解

    本篇文章是对VC解析XML文件-CMarkup的使用进行了详细的分析介绍,需要的朋友参考下 VC解析XML文件的工具有很多,CMarkup, tinyXML,还有IBM的,MS的等等. 据说tinyX ...

  6. Android 使用java.net.socket 的接收问题

    // 初始化socketsocket = new Socket(InetAddress.getByName(sip), sport);InputStream sin = socket.getInput ...

  7. Android自定义Seekbar拖动条式样

    SeekBar拖动条可以由用户控制,进行拖动操作.比如,应用程序中用户需要对音量进行控制,就可以使用拖动条来实现. 1.SeekBar控件的使用 1.1SeekBar常用属性 SeekBar的常用属性 ...

  8. [转]Raspberry Pi做成路由器

    http://raspjason.blog.51cto.com/8565009/1426561/ 曾经看到很多文章把Raspberry Pi制作成无线AP,但是我今天要做的是把Raspberry Pi ...

  9. nlog(n)解动态规划--最长上升子序列(Longest increasing subsequence)

    最长上升子序列LIS问题属于动态规划的初级问题,用纯动态规划的方法来求解的时间复杂度是O(n^2).但是如果加上二叉搜索的方法,那么时间复杂度可以降到nlog(n).  具体分析参考:http://b ...

  10. C#集合 -- Equality和Order插件

    在前面的文章C#相等性比较和C#排序比较中,我已经叙述了类型相等,类型哈希,和类型比较的.NET标准协议.实现了这些协议的类型在一个字典或者列表中也可以正常工作.但是需要注意的是: 只有当类型的Equ ...