这里介绍android的一些资源文件。

以一个登录界面为例。

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"> <TextView
android:textColor="@color/text_color"
android:textSize="@dimen/text_size"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_name" /> <EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"> <TextView
android:textColor="@color/text_color"
android:textSize="@dimen/text_size"
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password" /> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"> <Button
android:textColor="@color/button_color"
android:textSize="@dimen/button_size"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login" /> <Button
android:textColor="@color/button_color"
android:textSize="@dimen/button_size"
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancle" />
</LinearLayout>
</LinearLayout>

res/values下面有许多xml文件。colors.xml是存放颜色的文件。引用它可以@color/text_color,里面的颜色可以自己添加,name可以自己定义,最好可以看出你要引用的地方,方便阅读与修改。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="text_color">#0000ff</color>
<color name="button_color">#00ff00</color>
</resources>

strings.xml里面保存的是一些字符串,引用方式@string/text_name,同样是通过name进行引用的,所以name要能有代表性

<resources>
<string name="app_name">ResouceTest</string>
<string name="user_name">用户名</string>
<string name="password">密码</string>
<string name="cancle">取消</string>
<string name="login">登录</string>
</resources>

资源文件里可能没有之存放的地方,我们可以自己建一个Values XML files,创建方法和layout XML创建方法相同。建一个values.xml,然后里面存放一些值,比如说text_size

<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">18dp</dimen>
<dimen name="button_size">23dp</dimen>
</resources>

将这些文件归类,便于维护和修改。

第二十五篇-Android 应用资源的更多相关文章

  1. Android UI开发第二十九篇——Android中五种常用的menu(菜单)

    Android Menu在手机的应用中起着导航的作用,作者总结了5种常用的Menu. 1.左右推出的Menu 前段时间比较流行,我最早是在海豚浏览器中看到的,当时耳目一新.最早使用左右推出菜单的,听说 ...

  2. 第二十五篇:在SOUI中做事件分发处理

    不同的SOUI控件可以产生不同的事件.SOUI系统中提供了两种事件处理方式:事件订阅 + 事件处理映射表(参见第八篇:SOUI中控件事件的响应) 事件订阅由于直接将事件及事件处理函数连接,不存在事件分 ...

  3. Python之路(第二十五篇) 面向对象初级:反射、内置方法

    [TOC] 一.反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它 ...

  4. flask第二十五篇——控制语句

    有兴趣的请加船长公众号:自动化测试实战 先和大家强调一个发邮件的问题 # coding: utf-8 import smtplib from email.mime.text import MIMETe ...

  5. 第二十五篇:使用 sigaction 函数实现可靠信号

    前言 在前文中,讲述了一个可靠信号的示例.它分成几个步骤组成( 请参考前文 ).在 Linux 系统编程中,有个方法可以将这些步骤给集成起来,让我们使用起来更加的方便. 那就是调用 sigaction ...

  6. SpringBoot非官方教程 | 第二十五篇:2小时学会springboot

    转载请标明出处: http://blog.csdn.net/forezp/article/details/61472783 本文出自方志朋的博客 一.什么是spring boot Takes an o ...

  7. 第二十五篇 jQuery 学习7 获取并设置 CSS 类

    jQuery 学习7 获取并设置 CSS 类   jQuery动态控制页面,那么什么是动态呢?我们就说一下静态,静态几乎又纯html+css完成,就是刷新页面之后,不会再出现什么变动,一个实打实的静态 ...

  8. 第二十五篇 -- C++宝典中的图书管理系统

    此篇文章是基于C++宝典写的图书管理系统,本人对其中的部分做了相应修改,并且以现有格式替代原有格式,使程序更加清晰明了.此程序运行在VS2017上. 系统设计 图书管理系统分为四个模块:图书管理模块. ...

  9. 第二十五篇 hashlib模块(* *)

    用于加密相关的操作,Python 3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法. 加密复杂程度: SHA1  ...

随机推荐

  1. jquery选择基础

    1 元素选择器 之前不熟悉的是如: $("input.cls1"); 这种用法 2 属性选择器 包含name属性的input元素, 如 $("input[name]&qu ...

  2. OSError: mysql_config not found

    使用Python3开发一个管理平台,用MySQL数据库存放元数据.使用pip安装mysqlclient模块时出现“OSError: mysql_config not found”错误. 解决: # a ...

  3. POJ 2112-Optimal Milking-二分答案+二分图匹配

    此题有多种做法. 使用floyd算法预处理最短路,二分答案,对于每一个mid,如果距离比mid小就连边, 注意把每个机器分成m个点.这样跑一个最大匹配,如果都匹配上就可以减小mid值. 用的算法比较多 ...

  4. 使用python和selenium写一个百度搜索的case

    今天练习的内容主要写了一个小功能,在百度上搜索某词汇,然后实现web上的back功能 代码如下: import unittest from selenium import webdriver from ...

  5. hdu 4825 Xor Sum (01 Trie)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4825 题面: Xor Sum Time Limit: 2000/1000 MS (Java/Others) ...

  6. linux tar 解压命令

    如果提示 common not find 先进行安装如下 wget http://www.rarsoft.com/rar/rarlinux-5.3.0.tar.gz tar -zxvf rarlinu ...

  7. Android studio preview界面无法预览,报错render problem

    1.查看报错信息,如果有报错,该叹号应为红色,点击查看报错,显示为render problem 2.打开res/styles.xml修改为如图,添加Base. 3.再打开preview界面

  8. nmap 常用命令

    10.1.1.0/24 = 10.1.1.1-10.1.1.255       #c段扫描10.1.1.0/16 = 10.1.1.1-10.1.255.255   #b段扫描10.1.1.0/8 = ...

  9. Codeforces Round #429 (Div. 1) C. On the Bench(dp + 组合数)

    题意 一个长度为 \(n\) 的序列 \(A\) ,定义一个 \(1\) 到 \(n\) 的排列 \(p\) 是合法的,当且仅当 \(\forall i \in [1, n − 1], A_{p_i} ...

  10. 【BZOJ3874】[AHOI&JSOI2014]宅男计划(贪心,三分)

    [BZOJ3874][AHOI&JSOI2014]宅男计划(贪心,三分) 题面 BZOJ 洛谷 题解 大力猜想一最长的天数和购买外卖的总次数是单峰的.感性理解一下就是买\(0\)次是\(0\) ...