国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Android 開發使用PopupWindow實現加載等待界面功能示例

瀏覽:36日期:2022-09-24 09:50:54

本文實例講述了Android 開發使用PopupWindow實現加載等待界面功能。分享給大家供大家參考,具體如下:

實現加載等待界面我用了兩種方式,一種是用PopupWindow實現,另一種便是用Activity實現。用Activity實現方法請見我的另一篇博客:

Android 使用Activity實現加載等待界面

首先看效果:

Android 開發使用PopupWindow實現加載等待界面功能示例

用PopupWindow實現此功能還是比較簡單的,首先我們寫一個布局,只有一個登錄按鈕,用于觸發等待界面:

<?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: 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.myapplication.MainActivity'> <Button android:text='登錄' android:layout_width='match_parent' android:layout_height='wrap_content' android:onClick='loginClick' android: /></LinearLayout>

然后為登錄按鈕添加監聽事件:

package com.wang.myapplication;import ...public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void loginClick(View v){ final PopupWindow popupWindow = new PopupWindow(); popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); View view = LayoutInflater.from(this).inflate(R.layout.popup,null); popupWindow.setContentView(view); popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.CENTER,0,0); new Handler().postDelayed(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, '登錄成功', Toast.LENGTH_SHORT).show(); popupWindow.dismiss(); } },2000); }}

其中彈出的PopupWindow需要一個布局,也就是簡單放入一個ProgressBar:

<?xml version='1.0' encoding='utf-8'?><RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='200dp' android:layout_height='200dp'> <ProgressBar android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_centerInParent='true'/></RelativeLayout>

大功告成,運行一下即可!!

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android控件用法總結》、《Android開發入門與進階教程》、《Android視圖View技巧總結》、《Android編程之activity操作技巧總結》、《Android數據庫操作技巧總結》及《Android資源操作技巧匯總》

希望本文所述對大家Android程序設計有所幫助。

標簽: Android
相關文章:
主站蜘蛛池模板: 固原市| 东阿县| 滨海县| 乌拉特前旗| 翁牛特旗| 双鸭山市| 阜南县| 汉源县| 许昌县| 普兰县| 綦江县| 彭山县| 宁南县| 商城县| 济南市| 得荣县| 长兴县| 金堂县| 拜城县| 陆良县| 永城市| 碌曲县| 云阳县| 精河县| 木兰县| 平塘县| 贞丰县| 合阳县| 澄江县| 富裕县| 双城市| 新绛县| 闸北区| 山阳县| 甘孜县| 桐庐县| 临城县| 厦门市| 彩票| 亚东县| 侯马市|