Android 開(kāi)發(fā)使用Activity實(shí)現(xiàn)加載等待界面功能示例
本文實(shí)例講述了Android 開(kāi)發(fā)使用Activity實(shí)現(xiàn)加載等待界面功能。分享給大家供大家參考,具體如下:
實(shí)現(xiàn)加載等待界面我用了兩種方式,一種是用PopupWindow實(shí)現(xiàn),另一種便是用Activity實(shí)現(xiàn)。用PopupWindow實(shí)現(xiàn)方法請(qǐng)見(jiàn)我的另一篇博客:
android使用PopupWindow實(shí)現(xiàn)加載等待界面
好了,下面開(kāi)始。先上效果:
基本原理就是在主界面點(diǎn)擊按鈕(以登錄按鈕為例)之后,打開(kāi)一個(gè)新的Activity,此Activity以對(duì)話框形式展示。首先,主界面(一個(gè)登錄按鈕以及它的監(jiān)聽(tīng)事件):
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.toprs.waitingpractice.MainActivity"> <Button android:text="登錄" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="loginClick" android:id="@+id/button2"/> </LinearLayout>
MainActivity.java
package com.toprs.waitingpractice; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void loginClick(View v){ Intent intent = new Intent(); intent.setClass(MainActivity.this,WaitingActivity.class); startActivity(intent); } }
接下來(lái)是彈出的新Activity,新的Activity及其布局:
waiting_activity.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="com.toprs.waitingpractice.MainActivity"> <Button android:text="登錄" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="loginClick" android:id="@+id/button2"/> </LinearLayout>
WaitingActivity.java
package com.tow.waitingpractice; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.widget.Toast; /** * Created by 39867 on 2017/4/18. */ public class WaitingActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loading_activity); new Handler().postDelayed(new Runnable() { @Override public void run() { WaitingActivity.this.finish(); Toast.makeText(WaitingActivity.this, "登錄成功", Toast.LENGTH_SHORT).show(); } },2000); } }
OK,運(yùn)行一下試試吧。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android WebView調(diào)用本地相冊(cè)的方法
這篇文章主要為大家詳細(xì)介紹了Android WebView調(diào)用本地相冊(cè)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12Android build.gradle版本名打包配置的方法
這篇文章主要介紹了Android build.gradle版本名打包配置的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02Android?WebView升級(jí)詳細(xì)操作指南
Android的WebView差異化很嚴(yán)重,下面這篇文章主要給大家介紹了關(guān)于Android?WebView升級(jí)的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-07-07android實(shí)現(xiàn)多線程下載文件(支持暫停、取消、斷點(diǎn)續(xù)傳)
本篇文章主要介紹了androids實(shí)現(xiàn)多線程下載文件,主要包括暫停、取消、斷點(diǎn)續(xù)傳等功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-02-02SimpleCommand實(shí)現(xiàn)圖片下載(二)
這篇文章主要為大家詳細(xì)介紹了SimpleCommand實(shí)現(xiàn)圖片下載,并顯示到ImageView控件上,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10Android利用CountDownTimer實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果
這篇文章主要為大家詳細(xì)介紹了Android利用CountDownTimer實(shí)現(xiàn)點(diǎn)擊獲取驗(yàn)證碼倒計(jì)時(shí)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03一文帶你深入理解Android Window系統(tǒng)
Android中的窗口系統(tǒng)是應(yīng)用程序用戶界面的核心組件之一,它負(fù)責(zé)管理可視化區(qū)域、處理用戶輸入事件以及與系統(tǒng)UI交互,本文將深入介紹與Android窗口系統(tǒng)相關(guān)的重要概念,需要的朋友可以參考下2023-10-10Android電池電量監(jiān)聽(tīng)的示例代碼
本篇文章主要介紹了Android電池電量監(jiān)聽(tīng)的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10使用ViewPager實(shí)現(xiàn)高仿launcher左右拖動(dòng)效果
今天用ViewPager這個(gè)類實(shí)現(xiàn)了同樣的左右拖動(dòng)效果,這樣代碼更少,但是效果是一樣的,ViewPager是實(shí)現(xiàn)左右兩個(gè)屏幕平滑地切換的一個(gè)類,它是Google提供的,有需要的朋友可以了解下2013-01-01