Android Android应用资源 | 学习笔记
Android应用资源
- 一、字符串资源
- 步骤
- 二、颜色资源
- 步骤
- 三、尺寸资源
- 步骤
- 四、数据资源
一、字符串资源
- 为了改善程序的可读性和维护成本,Android允许把应用中用到的各种资源:字符串资源、颜色资源、数据资源等集中放到res目录中定义,应用程序则可以直接使用这些资源定义的值。
- 字符串资源文件位于res/values目录下,根元素是< resources >< /resources >标记,在该元素中,使用< string >< /string >标记定义各字符串,其中,通过为< string >< /string >标记设置name属性来指定字符串的名称,在其实标记< string >和< /string >中间添加字符串内容。
提示使用用户名资源来完成。
步骤
在strings.xml文件中补充——
在activity_main.xml中加入——
完整的修改情况如下——
strings.xml:
<resources><string name="app_name">My Application</string><string name="user">用户名</string><string name="password">密码</string><string name="login">登录</string><string name="cancel">取消</string>
</resources>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/user"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.205"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.442" /><TextViewandroid:id="@+id/textView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/password"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.216"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><EditTextandroid:id="@+id/editTextTextPersonName"android:layout_width="wrap_content"android:layout_height="wrap_content"android:ems="10"android:inputType="textPersonName"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.651"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.434" /><EditTextandroid:id="@+id/editTextTextPersonName2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:ems="10"android:inputType="textPersonName"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.651"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/login"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.343"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.594" /><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/cancel"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintHorizontal_bias="0.721"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintVertical_bias="0.594" />
</androidx.constraintlayout.widget.ConstraintLayout>
二、颜色资源
- 颜色资源文件位于res/values目录下,根元素是< resources >< /resources >标记,在该元素中,使用< color >< /color >标记定义各颜色资源,其中,通过为< color >< /color >标记设置name属性来指定颜色资源的名称,在其实标记< color >和< /color >中间添加颜色值。
步骤
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources><color name="colorPrimary">#6200EE</color><color name="colorPrimaryDark">#3700B3</color><color name="colorAccent">#03DAC5</color><color name="textColor">#1f72cd</color><color name="btnColor">#13227a</color>
</resources>
在activity_main.xml对应位置引用,如——
android:textColor="@color/btnColor"
三、尺寸资源
- 颜色资源文件位于res/values目录下,根元素是< resources >< /resources >标记,在该元素中,使用< dimen >< /dimen >标记尺寸资源,其中,通过为< dimen >< /dimen >标记设置name属性来指定尺寸资源的名称,在其实标记< dimen >和< /dimen >中间添加定义一个尺寸常量。
- 尺寸资源是没有定义的,需要自己写一个文件。
步骤
dimen.xml——
<?xml version="1.0" encoding="utf-8"?>
<resources><dimen name="textSize">20dp</dimen><dimen name="btnSize0">33dp</dimen>
</resources>
在activity_main.xml对应位置引用,如——
android:textSize="@dimen/textSize"
四、数据资源
- 数组资源文件位于res/values目录下,根元素是< resources >< /resources >标记,在该元素中,包括以下三个子元素:
< arrary / >子元素 | 用于定义普通类型的数组 |
---|---|
< integer-array / > 子元素 | 用于定义整数数组 |
< string-array / >子元素 | 用于定义字符串数组 |
- 可以定义在strings.xml文件中
引用——可以通过Spinner引用
在Spinner种引用——
android:entries="@array/item"
Android Android应用资源 | 学习笔记相关推荐
- Android(java)学习笔记176: 远程服务的应用场景(移动支付案例)
一. 移动支付: 用户需要在移动终端提交账号.密码以及金额等数据 到 远端服务器.然后远端服务器匹配这些信息,进行逻辑判断,进而完成交易,返回交易成功或失败的信息给移动终端.用户提交账号. ...
- Android日常开发 - FlexboxLayout学习笔记
Android日常开发 - FlexboxLayout学习笔记 Android日常开发使用FlexboxLayout实现流式布局的效果,FlexboxLayout与h5中的flex使用十分相似,都是将 ...
- Android Studio下载搭建学习笔记01
Android Studio下载搭建学习笔记01 下载Android Studio 安装Android Studio 进入安装向导 选择安装组件 选择安装位置 选择文件菜单 等待安装 启动并配置And ...
- Android高级终端开发学习笔记(《疯狂Android讲义》第11章-第17章)
Android高级终端开发笔记 2021/6/19 下午 13:34开始 多媒体应用开发 Android支持的音频格式有:MP3 WAV 3GP等.支持的视频格式有MP4 3GP等. 多媒体数据既可以 ...
- Android高级终端开发学习笔记(《疯狂Android讲义》第2章-第10章)
Android疯狂讲义前10章知识点总结 /-------------------------10-31号晚上学习笔记----------------------------/ 在设置了最小支持版本为 ...
- [Android]Android P(9) WIFI学习笔记 - HAL (1)
目录 前文回顾 前言 入口 WifiNative 初始化 打开WIFI IWifiChip IWifiCond ISupplicant 前文回顾 WIFI学习笔记 - Framework (1) WI ...
- Android开源项目 资源 学习
转载了一个开源项目的文章,转载一篇有系统总结的文章.感谢博主的慷慨,让我们学习! Android开源项目系列汇总已完成,包括: Android开源项目第一篇--个性化控件(View)篇 Android ...
- Android的LMK机制学习笔记
初识Android的LMK机制 一.文章背景 1.1 LMK中kill进程的关键log(原生系统):![LMK中kill进程的关键log](https://img-blog.csdnimg.cn/78 ...
- Android开发艺术探索学习笔记 第二章IPC
最近将之前工作做本地的学习笔记上传一下 这里是Android艺术开发探索的前三章内容 文章目录 1. android的多进程模式 2. IPC基础概念介绍 2.1 Serializable 2.2Pa ...
- 我的Android进阶之旅------gt;Android中编解码学习笔记
编解码学习笔记(一):基本概念 媒体业务是网络的主要业务之间.尤其移动互联网业务的兴起,在运营商和应用开发商中,媒体业务份量极重,其中媒体的编解码服务涉及需求分析.应用开发.释放license收费等等 ...
最新文章
- 【RS】Improving Implicit Recommender Systems with View Data - 使用浏览数据提升隐式推荐系统...
- resource id 3 php,PHP Warning: stat(): stat failed for Resource id
- Windows 7 部署 Android 开发环境傻瓜式教程(Eclipse+ADT)
- OpenGL生成的法线贴图并增加光照
- 计算已经生活了多少天的小题目
- github设置中文_【Github】100+ Chinese Word Vectors 上百种预训练中文词向量
- 直播预告丨云时代的数据库客户端——CloudQuery最佳实践
- java iso-8859-1_如何在Java中的ISO-8859-1和UTF-8之间转换?
- Android sqlite数据库操作通用框架AHibernate(一)-CRUD示例和使用步骤
- GAN(Generative Adversarial Networks) 初步
- rdd分组聚合算子xxByKey,xxBy
- 项目工作总结——人脸建模方法研究
- 修改vscode代码字体大小
- CentOS7安装配置MongoDB4.4.4踩坑
- java 跨年 周计算公式_Java关于周跨年的周数计算
- C++ 使用fdk-aac对音频编码
- Linux命令行下设置黑底绿字
- 5mm超厚“爱马仕”羊毛袜!堪比足底小太阳,抗寒-10℃,99%抑菌防臭不闷汗!...
- 安防工程商遇六大挑战考验 能否披荆斩棘?
- go 库 viper 配置解析神器