第二十五篇-Android 应用资源
这里介绍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 应用资源的更多相关文章
- Android UI开发第二十九篇——Android中五种常用的menu(菜单)
Android Menu在手机的应用中起着导航的作用,作者总结了5种常用的Menu. 1.左右推出的Menu 前段时间比较流行,我最早是在海豚浏览器中看到的,当时耳目一新.最早使用左右推出菜单的,听说 ...
- 第二十五篇:在SOUI中做事件分发处理
不同的SOUI控件可以产生不同的事件.SOUI系统中提供了两种事件处理方式:事件订阅 + 事件处理映射表(参见第八篇:SOUI中控件事件的响应) 事件订阅由于直接将事件及事件处理函数连接,不存在事件分 ...
- Python之路(第二十五篇) 面向对象初级:反射、内置方法
[TOC] 一.反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它 ...
- flask第二十五篇——控制语句
有兴趣的请加船长公众号:自动化测试实战 先和大家强调一个发邮件的问题 # coding: utf-8 import smtplib from email.mime.text import MIMETe ...
- 第二十五篇:使用 sigaction 函数实现可靠信号
前言 在前文中,讲述了一个可靠信号的示例.它分成几个步骤组成( 请参考前文 ).在 Linux 系统编程中,有个方法可以将这些步骤给集成起来,让我们使用起来更加的方便. 那就是调用 sigaction ...
- SpringBoot非官方教程 | 第二十五篇:2小时学会springboot
转载请标明出处: http://blog.csdn.net/forezp/article/details/61472783 本文出自方志朋的博客 一.什么是spring boot Takes an o ...
- 第二十五篇 jQuery 学习7 获取并设置 CSS 类
jQuery 学习7 获取并设置 CSS 类 jQuery动态控制页面,那么什么是动态呢?我们就说一下静态,静态几乎又纯html+css完成,就是刷新页面之后,不会再出现什么变动,一个实打实的静态 ...
- 第二十五篇 -- C++宝典中的图书管理系统
此篇文章是基于C++宝典写的图书管理系统,本人对其中的部分做了相应修改,并且以现有格式替代原有格式,使程序更加清晰明了.此程序运行在VS2017上. 系统设计 图书管理系统分为四个模块:图书管理模块. ...
- 第二十五篇 hashlib模块(* *)
用于加密相关的操作,Python 3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法. 加密复杂程度: SHA1 ...
随机推荐
- asyncio并发编程
一. 事件循环 1.注: 实现搭配:事件循环+回调(驱动生成器[协程])+epoll(IO多路复用),asyncio是Python用于解决异步编程的一整套解决方案: 基于asynico:tornado ...
- python学习笔记(11)--测验3: Python基础语法(下) (第7周)
斐波那契数列计算 B 描述 斐波那契数列如下: F(0) = 0, F(1) = 1 F(n) = F(n-1) + F(n-2) 编写一个计算斐波那契数列的函数,采用递归方式,输出不超过n的所有斐波 ...
- Java Annotation详解 理解和使用Annotation
系统中用到了java注解: 查了一下如何使用注解,到底注解是什么: (1)创建方法:MsgTrace Java Class==> 在Create New Class中: name:输入MsgTr ...
- 用dbExpress页的SQLConnection1连接sql server2000怎么设置。 [问题点数:0分]
在d7或者c6已经支持了. 贡献一下我的代码吧:dbeConn:= TSQLConnection.Create(nil); dbeConn.Params.Clear; dbeC ...
- SpringBoot之文件下载
package org.springboot.controller; import org.springboot.constant.Constant; import org.springframewo ...
- vue axios 封装(一)
封装一: 'use strict' import axios from 'axios' import qs from 'qs' import NProgress from 'nprogress' im ...
- hibernate一对多映射文件的配置
其中一个Customer对应多个LinkMan Customer的映射文件 Customer.hbm.xml-------------->一对多 <?xml version="1 ...
- mysql-语法大全
DDL语句 库 创建 create database 库名 charset utf8; 删除 drop database 库名; 修改 alter database 库名 charset latin; ...
- Luogu4725 【模板】多项式对数函数(NTT+多项式求逆)
https://www.cnblogs.com/HocRiser/p/8207295.html 安利! #include<iostream> #include<cstdio> ...
- GGS-DDU HDU - 4966
GGS-DDU Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...