How to use Android Studio
This article mainly explains how to use Android Studio
step:
1. Create a project
- First click new - new project to create a new project
- Select the Android template you want to create, it is recommended to select empty activity (empty template), and then next
- Name: Give your project a name
- API level: Select the version of the Android virtual machine, the lower the version, the faster it will run
- For the rest, just follow the default, click finish
- (Because the version is different, the order of step 2 and step 3 may be exchanged, just pay attention to it)
- The android project is created and contains three main files
- Activity: Provides the interaction between the user and the screen, so that the user can operate, and implement the main Java code in it
- activity_main.xml: layout file, the view displayed by the Android UI interface, all controls are designed here
- AndroidManifest.xml: The manifest file of the Android application, which is the description file of the entire Android application
2. Introductory test
- We double-click to enter activity_main.xml
- First change android.support.constraint.ConstraintLayout to LinerLayout linear, which means a horizontal structure
- And adding android:orientation="vertical" means to place all components vertically
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
</LinearLayout>
copy
- Next add a text Testview and a button Button
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="学习安卓,你准备好了吗"
android:id="@+id/tv_android"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="准备好了"
android:id="@+id/bt_android"
android:onClick="Welcome"/>
</LinearLayout>
copy
Note: In order for Xiaobai to develop good habits, the id of each control must be rigorous, and he will know what it means when he sees it. It is best not to contain numbers.
- Click preview on the right to display the view
- Double-click to enter Mainactivity, we intend to click the button to pop up toast
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Welcome(View view) {
Toast.makeText(this, "欢迎来到安卓世界", Toast.LENGTH_SHORT).show();
}
}
copy
Note: setContentView(R.layout.activity_main); this sentence is layout binding
3. Open the phone simulator
- You don’t need to actually download it to the phone, you can see the realization effect of the APP we wrote directly in the simulator
- Internet connection required
- Click the triangle (run APP) button, then create a new simulator, select the option in the picture (choose a low resolution, run fast), and then next
- Next, select the selection selected in the figure, and then proceed to next
- Give your emulator a name and click finish
4. Effect display
- Click run, it takes a while
- Click the button, "Welcome to the Android world" pops up
So far the experiment is successful
There may be many friends who don't know what R is?
R is a class index class to index all files under the r file The index of the resource directory finds the corresponding static member through the index number
Hope it can help beginners
You can scan the QR code below to get more Android introductory materials for free! !
[Tencent technical team produced] Android zero-based entry to proficiency, Android Studio installation tutorial + a full set of Android basic tutorials
Android programming tutorial
Java language basics from entry to familiarity
Kotlin language basics from entry to familiarity
Android technology stack from entry to familiarity
Android Jetpack family bucket comprehensive learning
For novices, it may be difficult to install Android Studio. You can watch the following video and learn to install and run step by step.
Android Studio installation tutorial
With the learning of the Java stage, it is recommended to focus on video learning at this stage and supplement it with books to check for omissions. If you focus on books, you can type codes based on book explanations, supplemented by teaching videos to check for omissions. If you encounter problems, you can go to Baidu. Generally, many people will encounter problems when getting started, and they will give better answers.
It is necessary to master basic knowledge points, such as how to use the four major components, how to create a Service, how to layout, simple custom View, animation, network communication and other common technologies.
A full set of zero-based tutorials has been prepared for you, if you need it, you can add the QR code below to get it for free
A full set of Android basic tutorials