Popupwindow弹出窗口
来源:互联网 发布:英文网络用语缩写 编辑:程序博客网 时间:2024/05/04 22:02
代码很简单,没有和别的控件连用。布局自己随意定义,我的这个是最基础的,就直接上代码啦!
在MainActivity里
import android.content.Context;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.PopupWindow;import android.widget.Toast;public class MainActivity extends AppCompatActivity { private Context mContext = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = this; Button button = (Button) findViewById(R.id.but); button.setOnClickListener(newView.OnClickListener() { @Override public void onClick(View view) { showPopupWindow(view); } }); } private void showPopupWindow(View view) { // 一个自定义的布局,作为显示的内容 View contentView =LayoutInflater.from(mContext).inflate( R.layout.popupwindow, null); // 设置按钮的点击事件 Button button = (Button) contentView.findViewById(R.id.button ); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(mContext, "button is pressed", Toast.LENGTH_SHORT).show(); } }); final PopupWindow popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, true); // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框 // 我觉得这里是API的一个bug popupWindow.setBackgroundDrawable(getResources().getDrawable(R.mipmap.ic_launcher)); // 设置好参数之后再show popupWindow.showAsDropDown(view); }}
在主布局里
<Button android:id="@+id/but" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" />
在popupwindow布局里
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffff00"><TextView android:id="@+id/ttt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="弹出窗口"/> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>
阅读全文
0 0
- PopupWindow实现弹出窗口
- Android弹出窗口PopupWindow
- 弹出窗口popupwindow
- Android 弹出窗口 PopupWindow
- PopupWindow弹出窗口
- PopupWindow 弹出窗口
- Popupwindow弹出窗口
- android-PopupWindow弹出窗口 - 随心
- popupwindow使用(弹出窗口)
- 安卓弹出窗口popupwindow
- 3种弹出窗口dialog,popupWindow,ContextMenu
- android弹出窗口的实现(PopupWindow)
- android弹出窗口的实现(PopupWindow)
- 自定义按钮 点击弹出PopupWindow窗口
- 弹出小窗口,PopupWindow的使用
- android弹出窗口的实现(PopupWindow)
- android弹出窗口的实现(PopupWindow)
- android弹出窗口的实现(PopupWindow)
- 纯java手机通讯录
- Linux 文件系统常用命令
- JAVA 遇见HTML --------JSP篇(1)
- dpdk 定时器学习,例子剖析以及注意事项
- 文章标题
- Popupwindow弹出窗口
- simpleImageTool又一纯java的简单而功能强的专门图片水印、缩放库,给gif加水印也很简单
- Tree----- 257. Binary Tree Paths(二叉树从根节点开始的所有路径)
- 从工程外读取图片,并显示
- 异或运算的性质
- java接口和多态
- Codevs非难题汇总
- Ucloud 必读
- 解决php的session异步请求堵塞问题(采用xhprof性能分析)