Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android UI + Activity + Events

Android UI + Activity + Events

編輯:關於Android編程

Statement:

This archive is created by William Yi and it’s all the harvests which is properly shown to the freshmen of AS.

You can never copy this archive without permission!

Precondition

Can use basic part of java language smoothly such as the class, interface, exception and so on. Have succeed in downloading the JDK for Android and your version of Android Studio is needed to at least 2.0 or later. Eager to enjoy the hard , tiring but meaningful and helpful period during when will coming soon. Want to be a professional Android developer and follow the guidance of your tutor.

Basic Info about Android

Android is based on the IntelliJ Ideal which is a very good and powerful java platform and Android is the mobile operating system.

An Android app mainly contains four parts/module:

Activity BroadCastReciever ContentProvider Service

They mainly communicate with each by what we called ”intent” which is just like the message in OOP.

The process how an app is developed:

java android SDK tools resources files debug .apk file download

More detailed information can be found at the developer.android.com.

Four Important Modules

Activity

We always regard it as the UI of an app, and an well organized app always contains so many UIs/Activities. Each activity shows one unique function of a huge app.

For example: WeChat

Service

it is a component that runs in the background to perform long-running operations or to perform work for remote processes.

Content providers

A content provider manages a shared set of app data.

Broadcast receivers

It is a component that responds to system-wide broadcast announcements.

How do they communicate with ec?

Activities, services, and broadcast receivers are activated by an asynchronous message called an intent.

Intents bind individual components to each other at runtime(you can think of them as the messengers that request an action from other components)

Activity LifeCycle

This following picture shows the details about how an activity starts and how it stops or destroys by calling several different method.

If you have a good understanding about the lifecycle about android then you will have a deeper understanding about android and the structure of android.

這裡寫圖片描述

Layout(LinearLayout and RelativeLayout)

Linear Layout, just like it’s name, the layout is linearly independent with each other while Relative Layout is relevant to each other.

LinearLayout Example: ToggleButton and Switch(Function of Button)

activity_main.xml




    
    
    
    
    
    

MainActivity_java

package com.example.dell1.plumblossom;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {
    ToggleButton toggleButton;
    Switch aSwitch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toggleButton = (ToggleButton) findViewById(R.id.toggle);
        aSwitch= (Switch) findViewById(R.id.aSwitch);
        final LinearLayout changer = (LinearLayout) findViewById(R.id.changer);
        CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton button, boolean isChecked) {
                if(isChecked) {
                    changer.setOrientation(LinearLayout.VERTICAL);
                    toggleButton.setChecked(true);
                    aSwitch.setChecked(true);
                } else {
                    changer.setOrientation(LinearLayout.HORIZONTAL);
                    toggleButton.setChecked(false);
                    aSwitch.setChecked(false);
                }
            }
        };
        toggleButton.setOnCheckedChangeListener(listener);
        aSwitch.setOnCheckedChangeListener(listener);
    }
}

RelativeLayout Example: Plum Blossom

activity_main.xml




    
    
    
    
    
    
    
    
    
    

TextView and EditText

TextView is the place that you can show a string in a layout while EditTest is derive from it and EditTest itself could be writeable.

TextView Example: HelloWorld

It is very easy. I suppose all of you can show t on your own.

EditText Example: FriendlyUI, CheckButton




    
        
        
    

    
        
        
    

    
        
        
    

    
        
        
    

    
        
        
    

    

ImageView

ImageView Example: QuickContactBadge

activity_main.xml



    
    

MainActivity.java



    
    

Data and Time

Data and Time Example: DataPicker and TimePicker

activity_main.xml




    
    
    
    

Dialog Content

Remain to be an extension: Content Example: AlertDialog

Extension: AdapterView, SimpleAdapterView

Developing android just like a long journey in which you can harvest a lot as well as pain a lot. The hard you try, the greater progress you will make.

Hope all of you can have a wonderful beginning and insist on going after your dream about android.

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved