最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中Activity組件實例介紹

 更新時間:2022年01月16日 14:37:21   作者:小白小鄭  
大家好,本篇文章主要講的是Android中Activity組件實例介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下

Activity 概述

在 Android 應(yīng)用中,提供了 4 大基本組件,分別是 Activity、Service、BroadcastReceiver 和 ContentProvider。而 Activity 是 Android 應(yīng)用最常見的組件之一。Activity 的中文意思是活動。在 Android 中,Activity 代表手機或者平板電腦中的一屏,它提供了和用戶交互的可視化界面。在一個 Activity 中,可以添加很多組件,這些組件負責(zé)具體的功能。
在一個 Android 應(yīng)用中,可以有多個 Activity。這些 Activity 組成了 Activity 棧(Stack),當(dāng)前活動的 Activity 位于棧頂,之前的 Activity 被壓入下面,成為非活動 Activity,等待是否可能被恢復(fù)為活動狀態(tài)。

啟動 Activity 的兩種情況

①、在一個 Android 應(yīng)用中,只有一個 Activity 時,那么只需要在 AndroidManifest.xml 文件中對其進行備注,并且將其設(shè)置為程序的入口。這樣,當(dāng)運行時,將自動啟動該 Activity。
②、在一個 Android 應(yīng)用中,存在多個 Activity 時,需要應(yīng)用 startActivity() 方法來啟動需要的 Activity。

關(guān)閉 Activity

在 Android 中,如果想要關(guān)閉當(dāng)前的 Activity,可以使用 Activity 類提供的 finish()方法。

舉例說明:啟動和關(guān)閉 Activity
核心代碼如下

// MainActivity
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

        TextView password = (TextView) findViewById(R.id.wang_mima);
        password.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //創(chuàng)建 Intent 對象
                Intent intent = new Intent(MainActivity.this,PasswordActivity.class);
                //啟動 PasswordActivity
                startActivity(intent);
            }
        });
    }
}
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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"
    tools:context=".MainActivity"
    android:background="#CCCC99"
    android:stretchColumns="0,3">

    <!-- 第一行 -->
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:paddingTop="200dp"
        >
        <TextView />
        <TextView
            android:text="賬號:"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:textSize="15dp"
            />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15dp"
            android:hint="郵箱或手機號"
            />
        <TextView/>
    </TableRow>

    <!-- 第二行 -->
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:paddingTop="2dp">
        <TextView />
            <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textSize="15dp"
                android:text="密碼"
                android:gravity="center_horizontal"
                />
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="輸入 6-16 位數(shù)字或字母"
                android:textSize="15dp"
                />
        <TextView/>
    </TableRow>

    <!-- 第三行 -->
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">
        <TextView/>
            <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="注冊"
                />
            <Button
                android:layout_width="15dp"
                android:layout_height="wrap_content"
                android:text="登錄"
                />
        <TextView/>
    </TableRow>

    <!-- 第四行 -->
    <TableRow
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:paddingTop="15dp"
        >
        <TextView />
        <TextView />
        <TextView
            android:id="@+id/wang_mima"
            android:text="忘記密碼?"
            android:textColor="#FF4500"
            android:gravity="right"
            />
    </TableRow>

</TableLayout>

所得 主界面

結(jié)果

//創(chuàng)建新活動 PasswordActivity
package com.example.example61;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

public class PasswordActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_password);
        //獲得布局文件中的關(guān)閉按鈕
        ImageButton close = (ImageButton) findViewById(R.id.close);
        close.setOnClickListener(new View.OnClickListener(){
            @Override
            //關(guān)閉當(dāng)前 Activity
            public void onClick(View v) {
                finish();
            }
        });
    }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".PasswordActivity"
    android:background="#CCCC99">

    <ImageButton
        android:id="@+id/close"
        android:layout_width="60dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:background="#0099CC"
        android:padding="5dp"
        android:scaleType="centerInside"
        android:src="@drawable/a" />

    <TextView
        android:id="@+id/t1"
        android:layout_width="350dp"
        android:layout_height="40dp"
        android:layout_alignBottom="@+id/close"
        android:layout_alignParentRight="true"
        android:background="#0099CC"
        android:paddingHorizontal="120dp"
        android:text="找回密碼"
        android:textSize="25dp" />

    <TextView
        android:id="@+id/textview"
        android:layout_below="@+id/close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:layout_marginLeft="20dp"
        android:textSize="25dp"
        android:text="郵箱或手機號"
        />

    <EditText
        android:id="@+id/edittext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textview"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        android:hint="請輸入郵箱或手機號"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edittext"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:background="#0099C"
        android:text="提交" />


</RelativeLayout>

單擊找回密碼所得界面

結(jié)果

總結(jié)

到此這篇關(guān)于Android中Activity組件實例介紹的文章就介紹到這了,更多相關(guān)Android Activity組件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android中使用ContentProvider管理系統(tǒng)資源的實例

    Android中使用ContentProvider管理系統(tǒng)資源的實例

    這篇文章主要介紹了Android中使用ContentProvider管理系統(tǒng)資源的實例,講解了ContentProvider對系統(tǒng)中聯(lián)系人及多媒體資源的管理例子,需要的朋友可以參考下
    2016-04-04
  • Android 動態(tài)菜單實現(xiàn)實例代碼

    Android 動態(tài)菜單實現(xiàn)實例代碼

    這篇文章主要介紹了Android 動態(tài)菜單實現(xiàn)實例代碼的相關(guān)資料,這里附有實例代碼及實現(xiàn)效果圖,需要的朋友可以參考下
    2017-01-01
  • Android自定義實現(xiàn)可滑動按鈕

    Android自定義實現(xiàn)可滑動按鈕

    這篇文章主要為大家詳細介紹了Android自定義實現(xiàn)可滑動的按鈕,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Android調(diào)用系統(tǒng)圖庫獲取圖片的方法

    Android調(diào)用系統(tǒng)圖庫獲取圖片的方法

    這篇文章主要為大家詳細介紹了Android調(diào)用系統(tǒng)圖庫獲取圖片,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Android使用fragment實現(xiàn)左側(cè)導(dǎo)航

    Android使用fragment實現(xiàn)左側(cè)導(dǎo)航

    這篇文章主要為大家詳細介紹了Android使用fragment實現(xiàn)左側(cè)導(dǎo)航,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • Android燒錄指令fastboot簡介

    Android燒錄指令fastboot簡介

    fastboot 是作為 Android 系統(tǒng)編譯器的客戶端,編譯后位于 ./out/host/?Linux?-x86/bin/fastboot 目錄下,這篇文章主要介紹了Android燒錄指令fastboot簡介,需要的朋友可以參考下
    2024-01-01
  • Android init.rc文件詳解及簡單實例

    Android init.rc文件詳解及簡單實例

    這篇文章主要介紹了Android init.rc文件詳解及簡單實例的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • Flutter Http網(wǎng)絡(luò)請求實現(xiàn)詳解

    Flutter Http網(wǎng)絡(luò)請求實現(xiàn)詳解

    這篇文章主要介紹了Flutter Http網(wǎng)絡(luò)請求實現(xiàn)詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Android使用fastjson庫解析json字符串實戰(zhàn)

    Android使用fastjson庫解析json字符串實戰(zhàn)

    fastjson是一個Java語言編寫的高性能功能完善的JSON庫,它采用一種“假定有序快速匹配”的算法,把JSON?Parse的性能提升到極致,是目前Java語言中最快的JSON庫,Fastjson接口簡單易用,已經(jīng)被廣泛使用在緩存序列化、協(xié)議交互、Web輸出、Android客戶端等多種應(yīng)用場景
    2023-11-11
  • Android使用自定義View實現(xiàn)餅狀圖的實例代碼

    Android使用自定義View實現(xiàn)餅狀圖的實例代碼

    這篇文章主要介紹了Android使用自定義View實現(xiàn)餅狀圖的實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05

最新評論

宝清县| 泽州县| 永川市| 黄石市| 清原| 颍上县| 湘潭市| 永春县| 工布江达县| 右玉县| 定边县| 兴海县| 天水市| 德江县| 武宁县| 迭部县| 牟定县| 常山县| 华宁县| 九江县| 江油市| 吉木乃县| 景泰县| 翼城县| 桐城市| 夏河县| 彩票| 仙居县| 腾冲县| 莫力| 黄骅市| 密云县| 临西县| 阜阳市| 房山区| 正阳县| 平顶山市| 南澳县| 遂川县| 于都县| 石首市|