Android 开发使用PopupWindow实现加载等待界面功能示例
作者:LIFE_R 时间:2023-03-26 07:51:36
本文实例讲述了Android 开发使用PopupWindow实现加载等待界面功能。分享给大家供大家参考,具体如下:
实现加载等待界面我用了两种方式,一种是用PopupWindow实现,另一种便是用Activity实现。用Activity实现方法请见我的另一篇博客:
Android 使用Activity实现加载等待界面
首先看效果:
用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: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.myapplication.MainActivity">
<Button
android:text="登录"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loginClick"
android:id="@+id/button2"/>
</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:id="@+id/progressBar4"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
大功告成,运行一下即可!!
希望本文所述对大家Android程序设计有所帮助。
来源:https://blog.csdn.net/wangtaocsdn/article/details/70983877
标签:Android,PopupWindow,加载等待界面
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java多线程Thread类的使用详解
2023-11-11 13:08:11
![](https://img.aspxhome.com/file/2023/3/59013_0s.png)
Android Fragment概述及用法
2022-08-23 15:54:22
![](https://img.aspxhome.com/file/2023/5/138255_0s.gif)
基于CXF搭建webService的实例讲解
2023-07-02 10:41:34
C++链表节点的添加和删除介绍
2023-08-23 02:32:09
java 引用类型的数据传递的是内存地址实例
2023-11-29 15:13:53
![](https://img.aspxhome.com/file/2023/7/60557_0s.png)
Android支付宝支付的示例代码
2022-06-20 02:32:49
![](https://img.aspxhome.com/file/2023/7/94247_0s.png)
SpringBoot2.x 集成 Thymeleaf的详细教程
2021-07-31 18:18:23
![](https://img.aspxhome.com/file/2023/1/114041_0s.png)
Java使用MulticastSocket实现群聊应用程序
2021-09-23 12:12:29
![](https://img.aspxhome.com/file/2023/9/75669_0s.jpg)
如何基于SpringBoot部署外部Tomcat过程解析
2021-10-26 07:14:16
深入Android Handler,MessageQueue与Looper关系
2023-01-24 03:34:25
![](https://img.aspxhome.com/file/2023/8/103868_0s.jpg)
windows定时器配置执行java jar文件的方法详解
2023-04-17 16:40:21
![](https://img.aspxhome.com/file/2023/4/61544_0s.png)
C#使用Ado.net读取Excel表的方法
2022-04-22 02:01:47
Android 内存优化知识点梳理总结
2021-05-24 02:54:19
![](https://img.aspxhome.com/file/2023/4/137634_0s.png)
Android Studio实现简易计算器(表格布局TableLayout)
2021-11-17 23:20:07
![](https://img.aspxhome.com/file/2023/4/98624_0s.jpg)
C#字符串加密解密方法实例
2022-01-11 23:30:14
通过图例了解PowerDesigner使用方法
2021-06-05 23:16:24
![](https://img.aspxhome.com/file/2023/8/70558_0s.png)
使用 Lambda 取代 Android 中的匿名类
2023-11-16 14:01:04
![](https://img.aspxhome.com/file/2023/6/106616_0s.jpg)
C#使用DevExpress中的XtraCharts控件实现图表
2022-12-21 10:14:10
![](https://img.aspxhome.com/file/2023/7/102167_0s.png)
深入学习Java 热部署的知识
2023-10-16 18:23:24
![](https://img.aspxhome.com/file/2023/3/71673_0s.png)
Java跨域问题的处理详解
2021-07-05 12:55:18