Experiment four "Android Program design" task One experiment content
- Refer to Http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID, installing Android Studio
- Finish Hello World, ask to modify the contents of the Res directory, Hello World to show their school number, the number of students before and after a student, submit code run and code cloud GIT link, no study number to deduct points
- Learn Android Stuidio Debug app
Experimental steps
- Download Android Studio and follow the tutorial installation
When you create a new project, Mainactivity is not yet .java
a state and cannot be compiled. At this time the software will error, error such as. At that time tried several Baidu methods are useless, the last try again more than 10 times bar ... Finally started a .zip
file.
After the .zip
file is ready, you can start configuring the analog display. You can run the program after the configuration is complete. On request, .xml
Add the entry number information to the document. The results of the operation are as follows.
- Android Stuidio Debug
- Click to
run——>Debug‘app‘
step through the code. After you set a breakpoint, you can stop the run at the breakpoint and switch to the Debug window to see the parameter changes.
After run, the error message appears in the box below the screen, and as with idea, you can quickly change the adjustment at the error point according to the prompt.
Task two experimental content
- Build the project, run the textbook related code
- Create thirdactivity, display your own number in thirdactivity, modify the code to let mainactivity start thirdactivity
- Submit code to run and code cloud git link, to have a study number watermark, otherwise it will deduct points
Experimental steps
- Right-click
java
directory, select new——>Activity——>Gallery
, create an empty new activity, named Thirdactivity
.xml
add number information in and add code to Mainactivity
import android.content.Intent;Intent intent = new Intent(this,ThirdActivity.class); startActivity(intent);
Task three experimental contents
- Build the project, run the textbook related code
- Modify the code to let the toast message display its own learning number information
- Submit code to run and code cloud git link, to have a study number watermark, otherwise it will deduct points
Experimental steps
import android.widget.Toast;Toast toast = Toast.makeText(MainActivity.this, "20165322王瑶佳", Toast.LENGTH_LONG); toast.show();
Task Four experimental content
- Build the project, run the textbook related code
- Modify the layout so that the P290 page interface is different from the textbook
- Submit code to run and code cloud git link, to have a study number watermark, otherwise it will deduct points
Experimental steps
- To
.xml——>Design
adjust the layout, modify the .xml
code as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><android.support.constraint.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 "> <textview android:layout_width=" wrap_content "android:layout_height=" Wrap_content " android:text= "Hello world!20165322" app:layout_constraintbottom_tobottomof= "parent" App:layout_constra Inthorizontal_bias= "0.54" app:layout_constraintleft_toleftof= "parent" app:layout_constraintright_torightof= " Parent "app:layout_constrainttop_totopof=" parent "app:layout_constraintvertical_bias=" 0.032 "/> <bu Tton android:id= "@+id/button" android:layout_width= "wrap_content" android:layout_height= "wrap_content "Android:text=" button " tools:layout_editor_absolutex= "148DP" tools:layout_editor_absolutey= "422DP" tools:ignore= "Missingconstrain ts "/> <imageview android:id=" @+id/imageview "android:layout_width=" 180DP "android:layout_he ight= "276DP" app:srccompat= "@android:d rawable/btn_star_big_off" tools:layout_editor_absolutex= "102DP" tools:layout_editor_absolutey= "100DP" tools:ignore= "missingconstraints"/></ Android.support.constraint.constraintlayout>
Task Five experimental content
- Build the project, run the textbook related code
- Submit code to run and code cloud git link, to have a study number watermark, otherwise it will deduct points
Experimental steps
Package Cn.edu.besti.is.wyj.helloworld;import Android.support.v7.app.appcompatactivity;import Android.os.Bundle; Import Android.graphics.color;import Android.view.menu;import Android.view.view;public class MainActivity extends appcompatactivity {int counter = 0; int[] Colors = {color.black, Color.Blue, Color.cyan, Color.dkgray, Color.gray, Color.green, Color.ltgray, Color.magenta, Color.Red, Color.White, color.yellow}; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the action Bar if it//is present. Getmenuinflater (). Inflate (R.menu.menu_main, menu); return true; public void ChangeColor (view view) {if (counter = = colors.length) {counter = 0; } view.setbackgroundcolor (colors[counter++]); }}
<AnalogClock android:id="@+id/analogClock1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="90dp" android:onClick="changeColor" />
- Click on the clock on the simulator to change the color
- Running results such as:
Experimental summary
This experiment is about the application of Android studio, the first time you feel the fun of building a system. Actually do when still very confused force, but see experimental results and feel very magical.
Resources
- Androidstudio Application Debugging Techniques
- Error parsing XML
20165322 experimental Four "Android Programming"