Course Name
Mobile Internet development based on Android platform
Date of experiment
March 24, 2016
Name of the experimental project
Use of color, string resources
Location of the experiment
S3010
Type of experiment
-Verification Type √ design type-comprehensive type
Hours
4
The purpose and requirements of the experiment (the knowledge points which are involved in this experiment and are required to be mastered)
Purpose
- Learn how to use color and string resources in Android.
- Understand how size and layout resources are used in Android.
Requirements
- Use color resources for activity and view in project;
- Use string resources and understand the reference mechanism of string resources;
- Set the dimensions for the view components in Android;
- 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
Process
1. Create a project
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
3. New color resource color.xml
4. using resource colors and string resources
Four, the experimental results (the experimental source program list and operating results or experimental conclusions, experimental design drawings)
1234567891011121314151617181920 |
<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"
android:background=
"#00ffff"
tools:context=
".MainActivity"
>
<TextView
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:text=
"@string/hello_world"
android:gravity=
"center"
android:textSize=
"20sp"
android:textColor=
"@color/text_blue"
/>
</RelativeLayout>
|
2. Resources
12345678910111213141516171819202122232425262728293031 |
<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"
android:background=
"@drawable/ic_launcher"
tools:context=
".MainActivity"
>
<TextView
android:id=
"@+id/textView1"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentTop=
"true"
android:layout_centerHorizontal=
"true"
android:textSize=
"30sp"
android:layout_marginTop=
"15dp"
android:text=
"@string/gzcc"
/>
<Button
android:id=
"@+id/but1"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/textView1"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"22dp"
android:text=
"@string/find"
/> </RelativeLayout>
|
1234567891011121314151617181920212223242526272829 |
package
com.example.ziyuan;
import
android.os.Bundle;
import
android.app.Activity;
import
android.view.Menu;
import
android.view.View;
import android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.TextView;
public
class
MainActivity
extends
Activity {
TextView tv;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.but1);
btn.setOnClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View arg0) {
// TODO Auto-generated method stub
tv=(TextView)findViewById(R.id.textView1);
tv.setTextColor(TRIM_MEMORY_MODERATE);
}
});
}
|
Five, Experimental summary (analysis of the results of the experiment, experience and improvement of experimental ideas)
After this experiment, you can learn more about the use of Android experiment color, string resources, but the specific structure of Android still do not understand, in the future need to see more, more practice.
Experimental reviews
Experimental results
Guide Teacher Signature: Date
Experiment 4 use of color, string resources