【安卓】实验4 颜色、字符串资源的使用

实验报告


课程名称


基于Android平台移动互联网开发


实验日期


3月25日


实验项目名称


实验4 颜色、字符串资源的使用


实验地点


S30010


实验类型


□验证型    √设计型    □综合型


学  时


2


一、实验目的及要求(本实验所涉及并要求掌握的知识点)


目的:

  1. 掌握Android中颜色和字符串资源的使用方法。
  2. 理解Android中尺寸和布局资源的使用方法。

要求:

  1. 在工程中为Activity、View使用颜色资源;
  2. 使用字符串资源并理解字符串资源的引用机制;
  3. 为Android中的视图组件设定尺寸;
  4. 运用布局资源将界面上的组件放在指定的位置。

二、实验环境(本实验所使用的硬件设备和相关软件)


(1)PC机

(2)操作系统:Windows XP

(3)软件: Eclipse, JDK1.6,Android SDK,ADT


三、实验内容及步骤

  1. 1.        创建工程
  1. 2.        修改字符串资源

打开/res/values/strings.xml文件。

点击Add按钮,添加字符串,输入字符串的name 和value

新建的工程含有三个已有字符串

  1. 3.        新建颜色资源color.xml
  1. 4.        使用资源颜色和字符串资源

颜色:R.color.red_gb

字符串:R.strings.s

打开res/layout/activity_main.xml文件,修改代码如下

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

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world"

android:textColor="@color/red_bg"

android:textSize="30sp"

android:text_color="@values/color/" />

</RelativeLayout>

 


四、实验结果(本实验源程序清单及运行结果或实验结论、实验设计图)


代码:

Activity_main:

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

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

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#fff0f0f0"
>

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:paddingBottom="10.0dip" >

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="0.0"

android:focusable="true"

android:focusableInTouchMode="true"

android:orientation="vertical" >

<FrameLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:layout_marginTop="22.0dip" >

<ImageView

android:layout_width="57.0dip"

android:layout_height="57.0dip"

android:layout_gravity="center"

android:adjustViewBounds="true"

android:contentDescription="@null"

android:scaleType="centerCrop"

android:src="@drawable/setting_head_icon"
/>

<ImageView

android:layout_width="66.0dip"

android:layout_height="66.0dip"

android:layout_gravity="center"

android:adjustViewBounds="true"

android:contentDescription="@null"

android:scaleType="centerCrop"

android:visibility="visible" />

</FrameLayout>

<!--  android:src="@drawable/setting_head_border"
-->

<EditText

android:id="@+id/userNameText"

android:layout_width="fill_parent"

android:layout_height="50.0dip"

android:layout_marginLeft="12.0dip"

android:layout_marginRight="12.0dip"

android:layout_marginTop="15.0dip"

android:background="@color/input_color"

android:drawablePadding="15.0dip"

android:ems="10"

android:hint="@string/userName"

android:inputType="text"

android:paddingBottom="2.0dip"

android:paddingLeft="15.0dip"

android:paddingRight="15.0dip"

android:paddingTop="2.0dip"

android:singleLine="true"

android:textColorHint="#ff999999"

android:textSize="16.0sp" />

<EditText

android:id="@+id/passwdText"

android:layout_width="fill_parent"

android:layout_height="50.0dip"

android:layout_marginBottom="20.0dip"

android:layout_marginLeft="12.0dip"

android:layout_marginRight="12.0dip"

android:layout_marginTop="20.0dip"

android:background="@color/input_color"

android:drawablePadding="15.0dip"

android:ems="10"

android:hint="@string/passwd"

android:inputType="textPassword"

android:paddingBottom="2.0dip"

android:paddingLeft="15.0dip"

android:paddingRight="15.0dip"

android:paddingTop="2.0dip"

android:singleLine="true"

android:textColorHint="#ff999999"

android:textSize="16.0sp" />

<Button

android:id="@+id/bnLogin"

android:layout_width="fill_parent"

android:layout_height="50.0dip"

android:layout_marginLeft="12.0dip"

android:layout_marginRight="12.0dip"

android:background="@color/login_button"

android:singleLine="true"

android:text="@string/login"

android:textColor="#ffffffff"

android:textSize="18.0sp"
/>

</LinearLayout>

</LinearLayout>

</RelativeLayout>

Colors:

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

<resources>

<color name="input_color">#fff</color>

<color name="login_button">#3980F4</color>

</resources>

Strings:

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

<resources>

<string
name="app_name">shiyan4</string>

<string
name="action_settings">Settings</string>

<string
name="hello_world">Hello world!</string>

<string
name="login">登陆</string>

<string
name="userName">请输入账户</string>

<string
name="passwd">请输入密码</string>

</resources>

运行结果:(截图)


五、实验总结(对本实验结果进行分析,实验心得体会及改进意见)


此次实验学会了如何引用各种资源,比如字符串、图片、颜色等,同过这种引用,之后要改变颜色就只需在xml文件中统一改就可以了,让以后的维护更加方便。


实验评语


 


实验成绩


 


指导教师签名:              年   月   日

           
时间: 2024-08-04 11:28:18

【安卓】实验4 颜色、字符串资源的使用的相关文章

实验3 颜色、字符串资源的使用

实验报告 课程名称 基于Android平台移动互联网开发 实验日期 2016年3月25日 实验项目名称 实验3 颜色.字符串资源的使用 实验地点 S3010 实验类型 □验证型    √设计型    □综合型 学  时 2 一.实验目的及要求(本实验所涉及并要求掌握的知识点) [目的] 掌握Android中颜色和字符串资源的使用方法. 理解Android中尺寸和布局资源的使用方法. [要求] 在工程中为Activity.View使用颜色资源: 使用字符串资源并理解字符串资源的引用机制: 为And

实验4 颜色、字符串资源的使用

课程名称 基于Android平台移动互联网开发 实验日期 2016/3/31 实验项目名称 颜色.字符串资源的使用 实验地点 机房 实验类型 □验证型    √设计型    □综合型 学  时 两节课 一.实验目的及要求(本实验所涉及并要求掌握的知识点) 1.掌握Android中颜色和字符串资源的使用方法. 2.理解Android中尺寸和布局资源的使用方法. 二.实验环境(本实验所使用的硬件设备和相关软件) (1)PC机 (2)操作系统:Windows XP (3)软件: Eclipse, JD

实验四 颜色、字符串资源的使用

[目的] 掌握Android中颜色和字符串资源的使用方法. 理解Android中尺寸和布局资源的使用方法. [要求] 在工程中为Activity.View使用颜色资源: 使用字符串资源并理解字符串资源的引用机制: 为Android中的视图组件设定尺寸: 运用布局资源将界面上的组件放在指定的位置. [原理] Android资源管理机制. [过程] 1.建立虚拟机 2.建立一个名为Sokodu项目 3.修改字符串资源文件(string.xml),增加所需的字符串资源 4.在values文件下添加co

实验4 颜色、字符串资源的使用 实验报告

实验报告 课程名称 基于Android平台移动互联网开发 实验日期 2016.3.25 实验项目名称 颜色.字符串资源的使用 实验地点 S3010 实验类型 □验证型    √设计型    □综合型 学  时 2 一.实验目的及要求(本实验所涉及并要求掌握的知识点) 掌握Android中颜色和字符串资源的使用方法. 理解Android中尺寸和布局资源的使用方法. 二.实验环境(本实验所使用的硬件设备和相关软件) (1)PC机 (2)操作系统:Windows XP (3)软件: Eclipse,

安卓自定义状态栏颜色以与APP风格保持一致

我们知道IOS上的应用,状态栏的颜色总能与应用标题栏颜色保持一致,用户体验很不错,那安卓是否可以呢?若是在安卓4.4之前,答案是否定的,但在4.4之后,谷歌允许开发者自定义状态栏背景颜色啦,这是个不错的体验!若你手机上安装有最新版的qq,并且你的安卓SDK版本是4.4及以上,你可以看下它的效果: 实现此功能有两种方法: 1.在xml中设置主题或自定义style: Theme.Holo.Light.NoActionBar.TranslucentDecor Theme.Holo.NoActionBa

安卓实验四—碎片的使用

实验四 碎片使用 实验目的及要求: (1)     掌握:碎片的创建 (2)     理解:限定符概念 (3)     掌握:碎片使用 实验内容: 1. 打开实验三项目 2. 创建一个横屏界面 方法:在layout目录旁再创建一个同级别的layout-land目录,将activity_list.xml布局文件复制到layout-land中即可 3. 新增一个碎片DetailFragment,将新闻详情制作成碎片 4. 修改新闻详情的布局,将其中的控件用DetailFragment替换 5. 修改

安卓开发颜色对照表

安卓系统字体颜色代码and修改字体颜色 1.  在layout文件下的配置xml文件中直接设置字体颜色,通过添加 android:textcolor=“#FFFFFF”来变化颜色 但这样的效果只能让字体千篇一律的显示一种颜色. 2.  在activity中通过TextView tv=new TextView(this):实例化一个textview,通过setContentView(tv);将其加载到当前activity,设置要显示的内容String str=“想要显示的内容”:通过以下代码可以实

android源码大放送(实战开发必备),免费安卓demo源码,例子大全文件详细列表

免费安卓demo源码,例子大全文件详细列表 本列表源码永久免费下载地址:http://www.jiandaima.com/blog/android-demo 卷 yunpan 的文件夹 PATH 列表 卷序列号为 0000-73EC E:. │ jiandaima.com文件列表生成.bat │ 例子大全说明.txt │ 本例子永久更新地址~.url │ 目录列表2016.03.10更新.txt │ ├─前台界面 │ ├─3D标签云卡片热门 │ │ Android TagCloudView云标签

安卓旅途之——开发数独(一)

安卓旅途之——开发数独(一) 数独游戏简介 数独游戏,是一种数学智力拼图游戏,是“独立的数字游戏”的简称,源自18世纪末的瑞士,后在美国发展,在日本得以发扬光大. 数独游戏可以训练玩家的逻辑推理能力,不少教育者皆认为数独是锻炼脑筋的好方法. 其规则如下: 1.游戏会从一个部分带有数字的九宫格开始. 在9×9的大九宫格(即3格宽×3格高)方阵里,每一格又细分为一个小九宫格. 2.游戏开始,已给定若干数字,其它宫位留白,玩家需要自己按照逻辑推敲出剩下的空格里是什么数字. 3.填数字时必须满足以下条件