In this codelab, you'll learn how lớn build & run your first game huannghe.edu.vn app in the Java programming language. (If you're looking for the Kotlin version of this codelab, you can go here.)

What you must know already

This codelab is written for programmers & assumes that you know either the Java or Kotlin programming language. If you are an experienced programmer and adept at reading code, you will likely be able to follow this codelab, even if you don't have much experience with Java.

Bạn đang xem: Xuất File Apk Trong

What you"ll learn

How lớn use game huannghe.edu.vn Studio to build your app.How lớn run your ứng dụng on a device or in the emulator.How to add interactive buttons.How to lớn display a second screen when a button is pressed.

Use apk Studio and Java lớn write game huannghe.edu.vn apps

You write huannghe.edu.vn apps in the Java programming language using an IDE called huannghe.edu.vn Studio. Based on JetBrains' IntelliJ IDEA software, game huannghe.edu.vn Studio is an IDE designed specifically for apk development.

Note: This version of the codelab requires huannghe.edu.vn Studio 3.6 or higher.

To work through this codelab, you will need a computer that can run huannghe.edu.vn Studio 3.6 or higher (or already has game huannghe.edu.vn Studio 3.6 or higher installed).

2. Install app huannghe.edu.vn Studio

Note: This version of the codelab requires apk Studio 3.6 or higher.

You can tải về huannghe.edu.vn Studio 3.6 from the app huannghe.edu.vn Studio page.

huannghe.edu.vn Studio provides a complete IDE, including an advanced code editor & app templates. It also contains tools for development, debugging, testing, and performance that make it faster và easier lớn develop apps. You can use app huannghe.edu.vn Studio to chạy thử your apps with a large range of preconfigured emulators, or on your own điện thoại device. You can also build production apps and publish apps on the Google Play store.

Note: apk Studio is continually being improved. For the latest information on system requirements & installation instructions, see the huannghe.edu.vn Studio download page.

huannghe.edu.vn Studio is available for computers running Windows or Linux, và for Macs running macOS. The OpenJDK (Java Development Kit) is bundled with game huannghe.edu.vn Studio.

The installation is similar for all platforms. Any differences are noted below.

Accept the mặc định configurations for all steps, & ensure that all components are selected for installation.After the install is complete, the thiết đặt wizard downloads & installs additional components, including the huannghe.edu.vn SDK. Be patient, because this process might take some time, depending on your internet speed.When the installation completes, huannghe.edu.vn Studio starts, và you are ready lớn create your first project.

Troubleshooting: If you run into problems with your installation, see the game huannghe.edu.vn Studio release notes or Troubleshoot game huannghe.edu.vn Studio.

3. Task: Create your first project

In this step, you will create a new apk project for your first app. This simple phầm mềm displays the string "Hello World" on the screen of an huannghe.edu.vn virtual or physical device.

Here's what the finished tiện ích will look like:

*

What you"ll learn

How to create a project in game huannghe.edu.vn Studio.How to create an emulated apk device.How to lớn run your phầm mềm on the emulator.How to lớn run your ứng dụng on your own physical device, if you have one.

Step 1: Create a new project

Open huannghe.edu.vn Studio.In the Welcome to huannghe.edu.vn Studio dialog, click Start a new app huannghe.edu.vn Studio project.
*
Select Basic Activity (not the default). Click Next.
*
Give your application a name such as My First App.Make sure the Language is set to lớn Java.
*
Leave the defaults for the other fields.Click Finish.

After these steps, app huannghe.edu.vn Studio:

Creates a folder for your game huannghe.edu.vn Studio project called MyFirstApp. This is usually in a thư mục called huannghe.edu.vnStudioProjects below your home directory.Opens the code editor showing your project.

Step 2: Get your screen phối up

When your project first opens in game huannghe.edu.vn Studio, there may be a lot of windows and panes open. Lớn make it easier lớn get khổng lồ know app huannghe.edu.vn Studio, here are some suggestions on how to customize the layout.

If there's a Gradle window mở cửa on the right side, click on the minimize button () in the upper right corner lớn hide it.
*
Depending on the form size of your screen, consider resizing the pane on the left showing the project folders to take up less space.

At this point, your screen should look a bit less cluttered, similar khổng lồ the screenshot shown below.

*

Step 3: Explore the project structure and layout

The upper left of the game huannghe.edu.vn Studio window should look similar to the following diagram:

*

Based on you selecting the Basic Activity template for your project, app huannghe.edu.vn Studio has set up a number of files for you. You can look at the hierarchy of the files for your app in multiple ways, one is in Project view. Project view shows your files và folders structured in a way that is convenient for working with an huannghe.edu.vn project. (This does not always match the tệp tin hierarchy! to see the file hierarchy, choose the Project files view by clicking (3).)

Double-click the app (1) folder to expand the hierarchy of phầm mềm files. (See (1) in the screenshot.)If you click Project (2), you can hide or show the Project view. You might need to select View > Tool Windows lớn see this option.The current Project view selection (3) is Project > huannghe.edu.vn.

In the Project > huannghe.edu.vn view you see three or four top-level folders below your app folder: manifests, java, java (generated)res. You may not see java (generated) right away.

Expand the manifests folder.

This thư mục contains huannghe.edu.vnManifest.xml. This file describes all the components of your app huannghe.edu.vn app & is read by the app huannghe.edu.vn runtime system when your app is executed. 2. Expand the java folder. All your Java language files are organized here. The java folder contains three subfolders:

com.example.myfirstapp: This thư mục contains the Java source code files for your app.

com.example.myfirstapp (huannghe.edu.vnTest): This folder is where you would put your instrumented tests, which are tests that run on an app huannghe.edu.vn device. It starts out with a skeleton kiểm tra file.

com.example.myfirstapp (test): This thư mục is where you would put your unit tests. Unit tests don't need an huannghe.edu.vn device khổng lồ run. It starts out with a skeleton unit thử nghiệm file. 3. Expand the res folder. This folder contains all the resources for your app, including images, layout files, strings, icons, & styling. It includes these subfolders:

drawable: All your app's images will be stored in this folder.

layout: This folder contains the UI layout files for your activities. Currently, your ứng dụng has one activity that has a layout tệp tin called activity_main.xml. It also contains content_main.xml, fragment_first.xml, and fragment_second.xml.

menu: This folder contains XML files describing any menus in your app.

mipmap: This thư mục contains the launcher icons for your app.

navigation: This folder contains the navigation graph, which tells game huannghe.edu.vn Studio how khổng lồ navigate between different parts of your application.

values: This thư mục contains resources, such as strings and colors, used in your app.

Step 4: Create a virtual device (emulator)

In this task, you will use the apk Virtual Device (AVD) manager lớn create a virtual device (or emulator) that simulates the configuration for a particular type of app huannghe.edu.vn device.

The first step is lớn create a configuration that describes the virtual device.

In app huannghe.edu.vn Studio, select Tools > AVD Manager, or click the AVD Manager icon in the toolbar.
*
Click +Create Virtual Device. (If you have created a virtual device before, the window shows all of your existing devices and the +Create Virtual Device button is at the bottom.) The Select Hardware window shows a các mục of pre-configured hardware device definitions.Choose a device definition, such as Pixel 2, and click Next. (For this codelab, it really doesn't matter which device definition you pick).In the System Image dialog, from the Recommended tab, choose the latest release. (This does matter.)If a Download liên kết is visible next khổng lồ a latest release, it is not installed yet, và you need to download it first. If necessary, click the link to start the download, and click Next when it's done. This may take a while depending on your connection speed.

Note: System images can take up a large amount of disk space, so just download what you need.

In the next dialog box, accept the defaults, & click Finish.

The AVD Manager now shows the virtual device you added.

If the Your Virtual Devices AVD Manager window is still open, go ahead and close it.

Xem thêm: Kể Truyện Đêm Khuya - Nhân Quả Và Số Phận Con Người

Step 5: Run your phầm mềm on your new emulator

In apk Studio, select Run > Run ‘app' or click the Run icon in the toolbar.
*
The icon will change when your ứng dụng is already running.
*

If you get a dialog box stating "Instant Run requires that the platform corresponding khổng lồ your target device (huannghe.edu.vn N...) is installed" go ahead và click Install and continue.

In Run > Select Device, under Available devices, select the virtual device that you just configured. This thực đơn also appears in the toolbar.

*

The emulator starts và boots just like a physical device. Depending on the speed of your computer, this may take a while. You can look in the small horizontal status bar at the very bottom of app huannghe.edu.vn Studio for messages khổng lồ see the progress.

Messages that might appear briefly in the status bar

Gradle build running

*

Waiting for target device to come on line

*

Installing APK

*

Launching activity

*

Once your phầm mềm builds & the emulator is ready, game huannghe.edu.vn Studio uploads the app to the emulator & runs it. You should see your phầm mềm as shown in the following screenshot.

*

Note: It is a good practice lớn start the emulator at the beginning of your session. Don't close the emulator until you are done testing your app, so that you don't have khổng lồ wait for the emulator khổng lồ boot again. Also, don't have more than one emulator running at once, to reduce memory usage.

Step 6: Run your app on a device (if you have one)

What you need:

An app huannghe.edu.vn device such as a phone or tablet.A data cable khổng lồ connect your game huannghe.edu.vn device to your computer via the USB port.

Run your tiện ích on a device

To let huannghe.edu.vn Studio communicate with your device, you must turn on USB Debugging on your app huannghe.edu.vn device.

On apk 4.2 and higher, the huannghe.edu.vn options screen is hidden by default. To show huannghe.edu.vn options and enable USB Debugging:

On your device, open Settings > About phone & tap Build number seven times.Return khổng lồ the previous screen (Settings). huannghe.edu.vn options appears at the bottom of the list. Tap huannghe.edu.vn options.Enable USB Debugging.

Now you can connect your device and run the phầm mềm from app huannghe.edu.vn Studio.

Connect your device khổng lồ your development machine with a USB cable. On the device, you might need to agree lớn allow USB debugging from your development device.In game huannghe.edu.vn Studio, click Run
*
in the toolbar at the đứng top of the window. (You might need khổng lồ select View > Toolbar to see this option.) The Select Deployment Target dialog opens with the list of available emulators và connected devices.Select your device, và click OK. huannghe.edu.vn Studio installs the app on your device and runs it.

Note: If your device is running an apk platform that isn't installed in app huannghe.edu.vn Studio, you might see a message asking if you want khổng lồ install the needed platform. Click Install and Continue, then click Finish when the process is complete.

Troubleshooting

If you're stuck, quit app huannghe.edu.vn Studio and restart it.

If game huannghe.edu.vn Studio does not recognize your device, try the following:

Disconnect your device from your development machine và reconnect it.Restart huannghe.edu.vn Studio.

If your computer still does not find the device or declares it "unauthorized":

Disconnect the device.On the device, open Settings->huannghe.edu.vn Options.Tap Revoke USB Debugging authorizations.Reconnect the device khổng lồ your computer.When prompted, grant authorizations.

If you are still having trouble, kiểm tra that you installed the appropriate USB driver for your device. See the Using Hardware Devices documentation.

Check the troubleshooting section in the game huannghe.edu.vn Studio documentation.

Step 7: Explore the phầm mềm template

When you created the project and selected Basic Activity, huannghe.edu.vn Studio set up a number of files, folders, and also user interface elements for you, so you can start out with a working app & major components in place. This makes it easier to lớn build your application.

Looking at your ứng dụng on the emulator or your device, in addition to the Next button, notice the floating kích hoạt button with an thư điện tử icon.

*
If you tap that button, you'll see it has been phối up lớn briefly show a message at the bottom of the screen. This message space is called a snackbar, và it's one of several ways to lớn notify users of your phầm mềm with brief information.

*

At the đứng đầu right of the screen, there's a thực đơn with 3 vertical dots.

*
If you tap on that, you'll see that huannghe.edu.vn Studio has also created an options menu with a Settings item. Choosing Settings doesn't bởi anything yet, but having it mix up for you makes it easier to địa chỉ user-configurable settings lớn your app.
*

Later in this codelab, you'll look at the Next button and modify the way it looks và what it does.

4. Task: Explore the layout editor

Generally, each screen in your huannghe.edu.vn app is associated with one or more fragments. The single screen displaying "Hello first fragment" is created by one fragment, called FirstFragment. This was generated for you when you created your new project. Each visible fragment in an game huannghe.edu.vn app has a layout that defines the user interface for the fragment. Apk Studio has a layout editor where you can create và define layouts.

Layouts are defined in XML. The layout editor lets you define & modify your layout either by coding XML or by using the interactive visual editor.

Every element in a layout is a view. In this task, you will explore some of the panels in the layout editor, and you will learn how khổng lồ change property of views.

What you"ll learn

How lớn use the layout editor.How lớn set property values.How to add string resources.How to showroom color resources.

Step 1: open the layout editor

Find and mở cửa the layout thư mục (app > res > layout) on the left side in the Project panel.
*
Double-click fragment_first.xml.

Troubleshooting: If you don't see the tệp tin fragment_first.xml, confirm you are running app huannghe.edu.vn Studio 3.6 or later, which is required for this codelab.

The panels khổng lồ the right of the Project view comprise the Layout Editor. They may be arranged differently in your version of game huannghe.edu.vn Studio, but the function is the same.

*

On the left is a Palette (1) of views you can add to your app.

Below that is a Component Tree (2) showing the views currently in this file, và how they are arranged in relation khổng lồ each other.

In the center is the Design editor (3), which shows a visual representation of what the contents of the file will look like when compiled into an apk app. You can view the visual representation, the XML code, or both.

In the upper right corner of the thiết kế editor, above Attributes (4), find the three icons that look like this:
*
These represent Code (code only), Split (code + design), and Design (design only) views.Try selecting the different modes. Depending on your screen form size and work style, you may prefer switching between CodeDesign, or staying in Split view. If your Component Tree disappears, hide & show the Palette.

Split view:

*

At the lower right of the thiết kế editor you see + and - buttons for zooming in và out. Use these buttons khổng lồ adjust the kích thước of what you see, or click the zoom-to-fit button so that both panels fit on your screen.

*

The Design layout on the left shows how your app appears on the device. The Blueprint layout, shown on the right, is a schematic view of the layout.

Practice using the layout thực đơn in the vị trí cao nhất left of the thiết kế toolbar lớn display the design view, the blueprint view, & both views side by side.
*

Depending on the kích cỡ of your screen và your preference, you may wish lớn only show the Design view or the Blueprint view, instead of both.

Use the orientation icon to lớn change the orientation of the layout. This allows you to chạy thử how your layout will fit portrait và landscape modes.
*
Use the device menu to lớn view the layout on different devices. (This is extremely useful for testing!)

*

On the right is the Attributes panel. You'll learn about that later.

Step 2: Explore và resize the Component Tree

In fragment_first.xml, look at the Component Tree. If it's not showing, switch the mode to Design instead of Split or Code.

*

This panel shows the view hierarchy in your layout, that is, how the views are arranged in relation to each other. 2. If necessary, resize the Component Tree so you can read at least part of the strings. 3. Click the Hide icon at the đứng top right of the Component Tree.

*

The Component Tree closes. 4. Bring back the Component Tree by clicking the vertical label Component Tree on the left.

*

Step 3: Explore view hierarchies

In the Component Tree, notice that the root of the view hierarchy is a ConstraintLayout view.

Every layout must have a root view that contains all the other views. The root view is always a view group, which is a view that contains other views. A ConstraintLayout is one example of a view group. 2. Notice that the ConstraintLayout contains a TextView, called textview_first and a Button, called button_first.

*

If the code isn't showing, switch khổng lồ Code or Split view using the icons in the upper right corner.In the XML code, notice that the root element is . The root element contains a element & a element.

Step 4: Change property values

In the code editor, examine the properties in the TextView element.Click on the string in the text property, & you'll notice it refers khổng lồ a string resource, hello_first_fragment.huannghe.edu.vn:text="