2017-2018-2 20165330 Experimental Report on Android program design

Source: Internet
Author: User

Download and install Android Studio
    1. : Download Android Studio
    2. Installation Tutorial Reference Android Development Easy Tutorial
Experimental content Task One
    • Refer to the Java and Android Development Learning Guide (second Edition) (Epubit,java for Android 2nd), chapter 24th, complete Hello World, request to modify the contents of the Res directory, Hello world to display their own school number, The student number of a classmate before and after his own study number
    • Experimental process
    • Find the app next res目录 one, click on layout activity_main.xml , modify theandroid:text="Hello World!"
    • Source
<?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!20155329 20165330 20165331"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>
    • Run results
Task Two
    • Refer to the Java and Android Development Learning Guide (second Edition) (Epubit,java for Android 2nd), Chapter 25th:
      • Build the project, run the textbook related code
      • Create thirdactivity, display your own number in thirdactivity, modify the code to let mainactivity start thirdactivity
    • Experimental process
      • CreateThirdActivity
      • Modify MainActivity the code in
      • mainCreate thirdactivity_main.xml and modify android:text="Hello World!" content in
    • Mainactivity.java
package zyx.is.besti.edu.cn.helloworld;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.content.Intent;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Intent intent = new Intent(this,ThirdActivity.class);        startActivity(intent);    }    }
    • Thirdactivity_main.xml
<?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=".ThirdActivity">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="20165330张羽昕" /></android.support.constraint.ConstraintLayout>
    • Run results
Task Three
    • UI testing: Refer to the Java and Android Development Learning Guide (second Edition) (Epubit,java for Android 2nd), Chapter 26th:
      • Build the project, run the textbook related code
      • Modify the code to let the toast message display its own learning number information
    • Mainactivity.java
package zyx.is.besti.edu.cn.helloworld;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.Toast;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Toast toast=Toast.makeText(MainActivity.this, "20165330张羽昕",Toast.LENGTH_LONG);        toast.show();            }}
    • Run results
Task Four
    • Layout test: Refer to the Java and Android Development Learning Guide (second Edition) (Epubit,java for Android 2nd), Chapter 27th:
      • Build the project, run the textbook related code
      • Modify the layout so that the P290 page interface is different from the textbook
    • Activity_main.xml
<relativelayout 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 "android:paddingleft=" 2DP "android:paddingright=" 2DP "><Button Android:id= "@+id/cancelbutton" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android : text= "20165330" android:layout_margintop= "70DP" android:layout_alignparenttop= "true" Android:layout_centerhorizo Ntal= "true"/><buttonandroid:id= "@+id/savebutton" android:layout_width= "Wrap_content" android:layout_height = "Wrap_content" android:text= "Zhang Yuxin" android:layout_below= "@+id/cancelbutton" android:layout_alignleft= "@+id/ CancelButton "android:layout_alignstart=" @+id/cancelbutton "android:layout_margintop=" 23DP "/>< Imageviewandroid:layout_width= "150DP" android:layout_height= "150DP" android:layout_margintop= "45DP" Android:padding= "4DP" android:src= "@android:d rawable/ic_dialog_email" android:id= "@+id/imageview" android:layout_below= "@+id/savebutton" android:layout_centerhorizontal= "true"/><linearlayoutandroid:id= "@+id/filter_button_ Container "android:layout_width=" match_parent "android:layout_height=" Wrap_content "Android:layout_ Alignparentbottom= "true" android:gravity= "Center|bottom" android:background= "@android: Color/white" Android:o rientation= "Horizontal" ><button android:id= "@+id/filterbutton" android:layout_width= "Wrap_content" Android : layout_height= "fill_parent" android:text= "Filter"/><button android:id= "@+id/sharebutton" Android:layout_w Idth= "Wrap_content" android:layout_height= "fill_parent" android:text= "Share"/><button android:id= "@+id/del Etebutton "android:layout_width=" wrap_content "android:layout_height=" fill_parent "android:text=" Delete "/>&lt ;/linearlayout> <imagebutton android:id= "@+id/imagebutton" Android:laYout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" Android:layout_centerhorizontal= "true" android:layout_marginbottom= "160DP" app:srccompat= "@mipmap/ic_launc Her "/></relativelayout>
    • Run results
Task Five
    • Event Processing test: Refer to the Java and Android Development Learning Guide (second Edition) (Epubit,java for Android 2nd), Chapter 28th:
      • Build the project, run the textbook related code
    • Mainactivity.java
 Package Zyx.is.besti.edu.cn.helloworld;import Android.app.activity;import Android.graphics.color;import Android.os.bundle;import Android.view.menu;import Android.view.view;public class Mainactivity extends Activity {int Co    unter = 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++]); }}
    • 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="20dp"    android:paddingLeft="20dp"    android:paddingRight="20dp"    tools:context=".MainActivity">    <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" /></RelativeLayout>
    • Run results
Problems encountered and their solutions
    • When you run Android Studio, you find that the Java program you created has a Red J logo, a non-C identity

      Solution: Find a lot of methods on the Internet, refer to the Android studio to solve the unrecognized Java file (red j) problem, after the modification and restart the computer to open, found that successfully resolved

    • Toast's Maketext () method error

      Workaround: Refer to Android Toast Encyclopedia (five scenarios) to build your own toast, the final solution is to use the event handler in the main function, set a button to invoke the prompt.

2017-2018-2 20165330 Experimental Report on Android program design

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.