4

Android入门第33天-Android里的弹出式对话框

 1 year ago
source link: https://blog.csdn.net/lifetragedy/article/details/128028734
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Android入门第33天-Android里的弹出式对话框_TGITCIC的博客-CSDN博客

Android Studio里在4.0前有一种ProgressDialog,这个已经淘汰了。我们完全可以使用ProgressBar来取代。但是还有一种Dialog叫PopWindow,它是一种“可阻塞式Dialog”。即弹出后除非你给它一个“动作”否则就一直显示在那。

今天我们就来看看这种Dialog的使用,如下面界面截图。

13e0cf3e9f584438959cd8e874010cc5.png

PopWindow里是可以嵌套一个View的,这个View就好比我们之前学习的Adapter模式。你只要绘制好一个自己布局的View,然后使用:LayoutInflater.from(ctx).inflate(R.layout.item_popup, null, false);加载你的自定义View并使用PopupWindow popWindow = new PopupWindow(自定义View......)即可完成“嵌套”。

下面我们就来看实际例子。

23aaeb8a0b2d427bb0849aaf0459cadb.png
  1. 屏幕中间有一个【弹出Windows】的按钮
  2. 点击后该弹出内嵌2个子菜单,一个【汤姆】一个【杰瑞】;
  3. 在空白处点击屏幕,该弹出的窗口消失;
  4. 点击【汤姆】显示Toast;
  5. 点击【杰瑞】显示Toast并关闭弹出窗口;

item_popup.xml



newCodeMoreWhite.png

 activity_main.xml



newCodeMoreWhite.png

MainActivity.java



newCodeMoreWhite.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK