欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中Activity組件實例介紹

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

Activity 概述

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

啟動 Activity 的兩種情況

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

關閉 Activity

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

舉例說明:啟動和關閉 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>

所得 主界面

結果

//創(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);
        //獲得布局文件中的關閉按鈕
        ImageButton close = (ImageButton) findViewById(R.id.close);
        close.setOnClickListener(new View.OnClickListener(){
            @Override
            //關閉當前 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>

單擊找回密碼所得界面

結果

總結

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

相關文章

  • kotlin $ 字符串模版的使用詳解

    kotlin $ 字符串模版的使用詳解

    $ 在kotlin 中當做字符串模版使用,作用就是在字符串里面識別自己定義的字符,這篇文章主要介紹了kotlin $ 字符串模版的使用,需要的朋友可以參考下
    2024-01-01
  • Android Drawerlayout實現(xiàn)側滑菜單效果

    Android Drawerlayout實現(xiàn)側滑菜單效果

    這篇文章主要為大家詳細介紹了Android Drawerlayout實現(xiàn)側滑菜單效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android開發(fā)-之監(jiān)聽button點擊事件的多種方法

    Android開發(fā)-之監(jiān)聽button點擊事件的多種方法

    本篇文章主要是介紹了Android開發(fā)之監(jiān)聽button點擊事件的方法,Android開發(fā)-之監(jiān)聽button點擊事件的方法總結,有興趣的可以了解一下。
    2016-11-11
  • 深入解析Android中View創(chuàng)建的全過程

    深入解析Android中View創(chuàng)建的全過程

    這篇文章主要給大家深入的解析了關于Android中View創(chuàng)建的全過程,文中介紹的非常詳細,相信對大家會有一定的參考借鑒,需要的朋友們下面來一起學習學習吧。
    2017-03-03
  • Android使用ContentProvider初始化SDK庫方案小結

    Android使用ContentProvider初始化SDK庫方案小結

    這篇文章主要介紹了Android使用ContentProvider初始化SDK庫方案總結,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-04-04
  • android打開應用所在的市場頁面進行評分操作的方法

    android打開應用所在的市場頁面進行評分操作的方法

    這篇文章主要介紹了android打開應用所在的市場頁面進行評分操作的方法,涉及Android操作市場頁面評分效果的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-04-04
  • Android實現(xiàn)從相冊選擇照片功能

    Android實現(xiàn)從相冊選擇照片功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)從相冊選擇照片功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Android關于Glide的使用(高斯模糊、加載監(jiān)聽、圓角圖片)

    Android關于Glide的使用(高斯模糊、加載監(jiān)聽、圓角圖片)

    這篇文章主要為大家詳細介紹了Android關于Glide的使用,內(nèi)容豐富,高斯模糊、加載監(jiān)聽、圓角圖片希望大家可以掌握,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android中AOP的應用實踐之過濾重復點擊

    Android中AOP的應用實踐之過濾重復點擊

    這篇文章主要給大家介紹了關于Android中AOP的應用實踐之過濾重復點擊的相關資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-09-09
  • Android ProgressBar實現(xiàn)進度條效果

    Android ProgressBar實現(xiàn)進度條效果

    這篇文章主要為大家詳細介紹了Android ProgressBar實現(xiàn)進度條效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04

最新評論