1,activity的xml布局(布局中有个Button按钮,点击按钮弹出一个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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher_background"
tools:context=".MainActivity">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:onClick="click"
android:textSize="30sp"
android:text="弹窗Popupwindow"/>

</LinearLayout>
2,上图中有白色背景的popupwindow 的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/ll_popup">

<LinearLayout
android:id="@+id/ll_popup_content"
android:layout_width="600dp"
android:layout_height="400dp"
android:gravity="center"
android:background="@android:color/white">
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="250dp"
android:padding="10dp"
android:src="@drawable/fengjing"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="250dp"
android:padding="10dp"
android:src="@drawable/small"/>
</LinearLayout>

</LinearLayout>
3,MainActivity的代码实现:

public class MainActivity extends AppCompatActivity {
private View pop;

private LinearLayout ll_popup,ll_popup_content;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pop = View.inflate(this, R.layout.popupwindow_test, null);
ll_popup = pop.findViewById(R.id.ll_popup);
ll_popup_content = pop.findViewById(R.id.ll_popup_content);
ll_popup_content.setOnClickListener(null);//Linearloyout就不可点击了
}

public void click(View view) {
final PopupWindow popupWindow = new PopupWindow(pop, MATCH_PARENT, MATCH_PARENT);
ll_popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.TOP,0,0);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
//完全沉浸式
super.onWindowFocusChanged(hasFocus);
if (hasFocus && Build.VERSION.SDK_INT >= 19) {
View decorView = getWindow().getDecorView(http://www.my516.com);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
}
---------------------

最新文章

  1. ZOJ 3805 (树形DP)
  2. java中 set,list,array(集合与数组)相互转换
  3. LAMP网站架构方案分析
  4. 用户浏览器关闭cookie处理方法
  5. how tomcat works 读书笔记四 tomcat的默认连接器
  6. Java凝视Annotation
  7. HLJU 1223: 寻找区间和 (交替推进法)
  8. PHP die与exit的区别
  9. CUDA学习,环境配置和简单例子
  10. 2019年4月zstu月赛A: 我不会做
  11. Confluence 6 编辑站点欢迎消息
  12. tortoiseSVN版本合并(merge)
  13. WPF 创建自定义控件及自定义事件
  14. layui动态options
  15. JavaScript -- Document-open
  16. 【原创】when.js2.7.1源码解析
  17. 012-Go ORM框架之Gorm测试
  18. Python-Image 基本的图像处理操作
  19. 17.并发容器之ThreadLocal
  20. 【Leetcode】【Medium】Linked List Cycle

热门文章

  1. Spring——BeanFactory
  2. ZooKeeper可以用来做什么(转)
  3. 开源GIS软件 1
  4. web 文件上传组件 Plupload
  5. Android---keycode值以及相应名称
  6. windows脚本(VBS)之cmd命令行的妙用
  7. robin 今天来南大了
  8. 2017全面JAVA面试经历总结
  9. vim copy,find and replace
  10. B3402 [Usaco2009 Open]Hide and Seek 捉迷藏 最短路