1.PopupWindow实现:
private void showPopupWindow(int x, int y, int width, int height) {
TextView textView = new TextView(this);
textView.setText("Hello popupWindow");
textView.setBackgroundColor(Color.CYAN);
PopupWindow popupWindow = new PopupWindow(textView, width, height);
popupWindow.showAtLocation(getWindow().getDecorView(),
Gravity.NO_GRAVITY, x, y);
}
不能在onCreate中,否则会报错,需要View渲染完成后调用
2.Dialog实现
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//在指定位置显示对话框
showDialog(100, 100, 200, 200);
}
@Override
protected Dialog onCreateDialog(int id, Bundle args) {
return new AlertDialog.Builder(this)
.setTitle("Hello Dialog!")
.setMessage("Hello Dialog")
.create();
}
@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
switch (id) {
case 1: {
//设置对话框的属性
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.x = args.getInt("x");
lp.y = args.getInt("y");
lp.width = args.getInt("width");
lp.height = args.getInt("height");
lp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(0, 0, 0, 0)));
}
break;
default:
break;
}
super.onPrepareDialog(id, dialog, args);
}
private void showDialog(int x, int y, int width, int height) {
Bundle bundle = new Bundle();
bundle.putInt("x", x);
bundle.putInt("y", y);
bundle.putInt("width", width);
bundle.putInt("height", height);
showDialog(1, bundle);
}
}
分享到:
相关推荐
android 弹出窗口android 弹出窗口
AS写的PopupWindow demo blog:http://blog.csdn.net/shenyuanqing/article/details/48136639
一个android弹出窗口的demo,实现了动画
安卓弹出窗口,点击后关闭,对初学都还是有参考价值的
仿微信 弹出窗口 拍照上传 底部弹出
主要介绍了Android弹出窗口实现方法,涉及Android TextView及鼠标事件的响应相关技巧,需要的朋友可以参考下
Android应用源码之自定义弹出窗口的实现
炫酷的弹出窗口 动画效果非常不错
android 弹出 进度窗口
android 浮层,引导用户操作、弹出窗口界面设置、Style设置、半透明效果
AnyLayer,Android对话框弹出窗口.zip
代码实现了Android通过Activity实现底部滑动弹出窗口,在进行微信、qq、朋友圈分析及评论时,经常用到这种效果。本代码还包括WebView的操作、底部菜单导航栏及顶部滑动菜单的实现。
分享一个在android开发中的多级PopupWindow 弹出窗口实例,不知道这种多级的弹出窗口算不算是“嵌套”方式?因为它们之间确实是有着层级的关系,当PopupWindow被主界面按钮触发的时候,会被弹出第一级,在第一级中...
BottomMenu:底部弹出窗口
android 离开与关闭程序弹出窗口--对话窗口上的ICON图标
Android弹出式WebView处理程序 这是一个Android Studio项目,显示了如何处理Android Webview中的弹出窗口。 大多数开源浏览器不支持打开弹出窗口。 在许多网站(例如, )中使用的OAuth登录中,弹出窗口尤为重要。 ...