20165326 Experiment four-android programming one: Android Stuidio installation Test 1, install Android Stuidio
Follow the tutorial to go on the line is mainly configured to choose to download the SDK or manual configuration, detailed tutorial (note that standard is the default download, custom can make their own choice), then create a new project, the virtual device configuration and so on.
Problems encountered:Gradle Project sync failed.
Workaround: Go to the project directory, locate the gradle\wrapper\gradle-wrapper.properties file, Notepad open, and the last sentence:https://services.gradle.org/distributions/gradle-4.4-all.zip
Studio will download the above Gradle
We can manually download this version of the Gradle without having to unzip the copy directly to
C:\Users\Administrator\.gradle\wrapper\dists\gradle-4.4-all\9br9xq1tcpiv8o6njlyu5op1
Directory, restart Studio (attach the updated tutorial)
Initial knowledge of Android Studio
- The manifest file
AndroidManifest.xml , z where the packag attribute specifies an identifier for the application application , the element below describes the application, contains multiple activity elements (describes the activity in the app, has mainactivity as a portal
resDirectory:
Stores the various resources that the application uses, such as XML interface files, pictures, data, and so on.
- drawable: Storing pictures.
- Layout: Storing XML interface layouts file, mainly used for displaying user interface.
- Values: Store different types of data.
2, complete Hello World, modify the contents of the Res directory, Hello world to show their own school number, the number of a classmate before and after their study number
Step: Open the directory under Project View res activity——main.xml and TextView Modify the android:text contents below
Code
android:text="Hello World!20165326 20165325 20165327"
II: Activity test:
Reference Material 25th Chapter:
- Build the project, run the textbook related code
- Create thirdactivity, display your own number in thirdactivity, modify the code to let mainactivity start thirdactivity
Start another activity with one activity, usingstartActivity
method, you must first add the activity name to the new call under Manifest,
The code is as follows
<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".ThirdActivity"> </activity>
Then modify the contents of the . Java file
Main
@Override public boolean onTouch(View arg0, MotionEvent event) { Intent intent = new Intent(this, ThirdActivity.class); intent.putExtra("message", "20165326CZZZZZ"); startActivity(intent); return true; }
Open another activity by opening the main activity implementation as follows
Three: UI test:
Refer to Chapter 26
- Build the project, run the textbook related code
- Modify the code to let the toast message display its own learning number information
Code
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_marginTop="16dp" android:paddingLeft="16dp" android:paddingRight="16dp" android:text="20165326cz" android:id="@+id/btn1" />
Four: Layout test:
Refer to Chapter 27th:
- Build the project, run the textbook related code
-
Modify the layout so that the P290 page interface is different from the textbook
Code
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:layout_marginLeft="100dp" android:text="你的学号"/><ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/bottom_bar" android:alpha="0.35" android:layout_marginLeft="200dp" android:layout_marginTop="200dp"/>
You can actually add something else.
V: Event Processing test
Refer to Chapter 28th
- Build the project, run the textbook related code
Personal preference, added a Ratingbar
Reference: Java and Android Development Learning Guide (second Edition) (Epubit,java for Android 2nd)
20165326 Java Experiment Four