"Android" experiment 4 use of color, string resources

Source: Internet
Author: User

Lab Report

Course Name

Mobile Internet development based on Android platform

Date of experiment

March 25

Name of the experimental project

Experiment 4 use of color, string resources

Location of the experiment

S30010

Type of experiment

-Verification Type √ design type-comprehensive type

Hours

2

The purpose and requirements of the experiment (the knowledge points which are involved in this experiment and are required to be mastered)

Objective:

  1. Learn how to use color and string resources in Android.
  2. Understand how size and layout resources are used in Android.

Requirements:

  1. Use color resources for activity and view in project;
  2. Use string resources and understand the reference mechanism of string resources;
  3. Set the dimensions for the view components in Android;
  4. Use layout resources to place components on the interface at the specified location.

second, the experimental environment (the hardware equipment and related software used in this experiment)

(1) PC Machine

(2) Operating system: Windows XP

(3) Software: Eclipse, jdk1.6,android Sdk,adt

Third, the contents and steps of the experiment

    1. 1. Create a project
    1. 2. Modifying string resources

Open the/res/values/strings.xml file.

Click the Add button to add a string, enter the string name and value

A new project contains three existing strings

    1. 3. New color resource color.xml
    1. 4. using resource colors and string resources

Color: R.COLOR.RED_GB

String: R.STRINGS.S

Open the Res/layout/activity_main.xml file and modify the code as follows

<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>

Four, the experimental results (the experimental source program list and operating results or experimental conclusions, experimental design drawings)

Code:

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" > Login </string>

<string name= "UserName" > Please enter your account </string>

<string name= "passwd" > Please enter your password </string>

</resources>

Run Result: ()

Five, Experimental summary (analysis of the results of the experiment, experience and improvement of experimental ideas)

The experiment learned how to reference various resources, such as strings, pictures, colors, and so on, and then to change the color just in the XML file can be changed uniformly, so that later maintenance more convenient.

Experimental reviews

Experimental results

Guide Teacher Signature: Date

"Android" experiment 4 use of color, string resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.