Chapter 1 Getting Started with Android Basics:
1.1 Introduction to Android
- founder
Android was originally a mobile operating system founded by Andy Rubin (Andy Rubin) - Android Architecture
- application layer
is a collection of core applications, all applications installed on the phone belong to this layer - Application Framework Layer
Mainly provides various API s for building applications - Core library classes
Contains system libraries and runtime libraries - Linux kernel layer
Provides low-level drivers for various hardware of Android devices
3.Androi program structure
-
app: used to store the code and resources of the program, including many subdirectories
-
libs: used to store third-party jar packages
-
src/androidTest: code file for storing debugging
-
src/main/java: The code file used to store the program
-
src/main/res: resource files used to store programs
-
src/main/AndroidManifest.xml: The configuration file of the entire program, in this file you can configure the permissions required by the program and the four components used in the registration program
4.Dalvik virtual machine:
Designed by Google, a virtual machine that can run on the Android platform
Dalvik virtual machine is a register-based architecture
5. Management and use of resources
!!! There can only be one root element in an XML file
(1) Image resources -
Call image resources through java code
//The getResources().getDrawable() method calls image resources getResources().getDrawable(R.mipmap.ic_launcher);//Resource file that calls files starting with mipmap getResources().getDrawable(R.drawable.icon);//Resource file that calls files starting with drawable
- Calling image resources in XML layout file resources
@mipmap/ic_launcher @drawable/icon
(2) Theme and style resources
theme:
Theme resources are defined in the styles.xml folder under res/values
- The sample code for setting the theme in the AndroiManifest.xml file is as follows:
<application> ... android:theme="@style/AppTheme" </application>
- The sample code for setting the theme in the java code is as follows:
setTheme(R.style.AppTheme)
style:
Stored in the styles.xml folder of res.values
<resources> <style name=""> <item name=""> ... </style> </resources> //Set the name of the control in the name of the style, and set the style of the control in the item //In the textView control of the layout file, you can call it through @style/stylename
(3) Layout resources
- In java code:
setContentView(R.layout.activity_main)
- in the XML file
<include layout="R.layout.activity_main"/>
(4) String resources
Under the strings.xml folder of res.values:
<resources> <string name="appname"> string </string> </resources>
- In java file:
getResources().getString(R.string.appname)
- in the XML file
@string/appname
(5) Color resources
Stored in the colors folder of res.values
<color name="color1">#000000</color>
- In java file:
getResources().getColor(R.color.color1)
- In XML:
@color/color1
(6) Size resources
Under the res.values file, create dimen.xml
<resources> <dimen name="dimen1">16dp</dimen> </resources>
- in java file
getResources().getDimension(R.dimen.dimen1)
- in the xml file
@dimen/dimen1
1.2 Program debugging
1.2.1 Unit testing
- Android unit testing
- When using this method, an Android device needs to be connected, and the speed is relatively slow, which is suitable for unit tests that need to call Android API
- Junit unit tests
- No need to rely on Android devices, it can be run locally, with high speed, suitable for unit testing of Java code functions only
1.2.2 Use of Logcat
The log is divided into six levels, from low to high, respectively
Verbose (all logs), Debug, Info, Warning, Error, Assert (assert)
The corresponding static method is:
Log.v(),Log.d(),Log.i(),Log.w(),Log.e(),Log.wtf()
The colors displayed on the console are:
black, black, black, blue, red, red
Part of the XML control explanation:
android:layout_columnSpan="2"//spans two columns
The number of rows occupied by the current control:
android:layout_rowSpan="3"
exercise
Which of the following statements about the AndroidManifest.xml file is false (D).
A. It is the configuration file for the whole program
B. The permissions required by the program can be configured in this file
C. You can register the components used by the program in this file
D. This file can set the UI layout
Each Dalvik virtual machine instance is an independent process space, and each process cannot communicate with each other ×