Android UI:PopupWindow基本学习
来源:互联网 发布:ddos攻击防御软件 编辑:程序博客网 时间:2024/05/19 18:42
什么是PopupWindow?
就是点击某个控件,弹出个view,弹出的view就是PopupWindow效果图:点击button,弹出PopWindow,里面又有4个button,点击第一个button,弹出toast。
<?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:orientation="vertical" > <Button android:id="@+id/btn_pop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn01" android:textSize="20px" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn02" android:textSize="20px" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn03" android:textSize="20px" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="btn0" android:textSize="20px" /></LinearLayout>
3 代码
package com.examp.popupwindowdemo;import android.os.Bundle;import android.app.Activity;import android.graphics.Color;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.ColorDrawable;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.LinearLayout;import android.widget.PopupWindow;import android.widget.Toast;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn=(Button) findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {//打开popupwindowshowPopupWindow(v);}}); } protected void showPopupWindow(View v) {View contentView = View.inflate(getApplicationContext(), R.layout.popwindow, null);PopupWindow popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);popupWindow.setTouchable(true);//popupwindow可点击popupWindow.setOutsideTouchable(true);//popupwindow以外的地方可点击,使其调用dismiss()方法,不设置这个点击popupwindow以外的区域pop不会消失popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//必须设置Drawable背景(2中方法)//popupWindow.setBackgroundDrawable(new BitmapDrawable());Button btn_pop=(Button) contentView.findViewById(R.id.btn_pop);btn_pop.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(getApplicationContext(), "pop弹出toast", Toast.LENGTH_LONG).show();}});popupWindow.showAsDropDown(v);}}
其他弹框
[Dialog](http://blog.csdn.net/ss1168805219/article/details/52489259?locationNum=2&fps=1)[PopupWinow](http://blog.csdn.net/ss1168805219/article/details/50539919)[Spinner](http://blog.csdn.net/ss1168805219/article/details/52799813?locationNum=3&fps=1)
0 0
- Android UI:PopupWindow基本学习
- Android UI设计:PopupWindow
- android UI(1)-PopupWindow
- Android UI 之 PopupWindow
- Android UI PopupWindow 简单使用
- Android中的PopupWindow基本使用
- Android学习手记(5) 基本UI布局
- Android之基本UI的学习
- android学习之popupWindow
- Android学习之PopupWindow
- Android学习之PopupWindow
- Android UI设计--PopupWindow显示位置设置
- Android UI开发第三篇-PopupWindow
- [阶段二]Android UI PopupWindow组件
- Android学习——PopupWindow
- 【学习笔记】Android PopupWindow使用
- android基础学习之popupwindow
- Android中PopupWindow的基本使用
- 初学MFC,用笨办法实现CString和char之间的转换
- Android UI集锦——1.Android Drawable分类汇总(2/3)
- 19-mysql优化之定时维护
- Atitit 文件上传 架构设计 实现机制 解决方案 实践java php c#.net js javascript c++ python
- Android UI集锦——1.Android Drawable分类汇总(3/3)
- Android UI:PopupWindow基本学习
- 响应式web----viewport
- 智能监控效果图
- Automatic and No automatic
- IOS shareSDK 集成引入库以及问题
- Atitit.数据索引 的种类以及原理实现机制 索引常用的存储结构
- ST-Link驱动安装不正确,设备管理器黄色感叹号,win10安装stlink驱动
- RESTful Web API 具有怎样的特征
- Swift访问Foundation框架