AlertDialog && PopupWindow[已解决]


AlertDialog 
AlertDialog aDialog;
setAlertDialog();
aDialog.show();

protected void setAlertDialog() {
// TODO Auto-generated method stub
final String[] items = getResources().getStringArray(R.array.alarm_type_item);
AlertDialog.Builder ab = new AlertDialog.Builder(this)
.setTitle("请点击选择").setItems(items, multiClick);
aDialog = ab.create();
}

private DialogInterface.OnClickListener multiClick = new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

Toast.makeText(MainActivity.this, "第" + (which) + "项选中",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
if (which == 0)
{
intent.setClass(MainActivity.this,AddQuickNormalAlarm.class);
MainActivity.this.startActivity(intent);
}
}

};

转:
ab.setTitle("HelloAlert").setMessage("Warning: its Alert Demo!").setIcon(R.drawable.robot);
  1. builder.setIcon(R.drawable.icon);   
  2. 53.        builder.setTitle("Title");   
  3. 54.        builder.setMessage("Message");   
  4. 55.        builder.setPositiveButton("Button1",   
  5. 56.                new DialogInterface.OnClickListener() {   
  6. 57.                    public void onClick(DialogInterface dialog, int whichButton) {   
  7. 58.                        setTitle("点击了对话框上的Button1");   
  8. 59.                    }   
  9. 60.                });   
  10. 61.        builder.setNeutralButton("Button2",   
  11. 62.                new DialogInterface.OnClickListener() {   
  12. 63.                    public void onClick(DialogInterface dialog, int whichButton) {   
  13. 64.                        setTitle("点击了对话框上的Button2");   
  14. 65.                    }   
  15. 66.                });   
  16. 67.        builder.setNegativeButton("Button3",   
  17. 68.                new DialogInterface.OnClickListener() {   
  18. 69.                    public void onClick(DialogInterface dialog, int whichButton) {   
  19. 70.                        setTitle("点击了对话框上的Button3");   
  20. 71.                    }   
  21. 72.                });   



函数
简介
showAsDropDown(View anchor)相对某个控件的位置(正左下方),无偏移
showAsDropDown(View anchor, int xoff, int yoff)相对某个控件的位置,有偏移
showAtLocation(View parent, int gravity, int x,inty)父容器容器相对位置,例如正中央Gravity.CENTER,下方Gravity.BOTTOM等

PopupWindow pWindow;
setPopupWindow();
pWindow.showAsDropDown(v);

private void setPopupWindow() {
if (null != pWindow) {
pWindow.dismiss();
return;
} else
initPopuptWindow();
}
protected void initPopuptWindow() {
// TODO Auto-generated method stub
// 获取自定义布局文件pop.xml的视图
View popupWindow_view = getLayoutInflater().inflate(R.layout.appendix,
null, false);
// 创建PopupWindow实例,200,150分别是宽度和高度
pWindow = new PopupWindow(popupWindow_view, 50, 150, true);
// 设置动画效果
// pWindow.setAnimationStyle(R.style.AnimationFade);
// 点击其他地方消失
popupWindow_view.setOnTouchListener(new OnTouchListener() {
// @Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (pWindow != null && pWindow.isShowing()) {
pWindow.dismiss();
pWindow = null;
}
return false;
}
});
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值