对话框 PopupWindow 相关
来源:互联网 发布:什么是人工智能 编辑:程序博客网 时间:2024/06/06 06:33
1.自定义Dialog 弹出
noCardDialog=new NoCardDialog(context); Window noCardDialogWindow=noCardDialog.getWindow(); WindowManager.LayoutParams lp=noCardDialogWindow.getAttributes(); noCardDialogWindow.setGravity(Gravity.CENTER); lp.width=300; noCardDialogWindow.setAttributes(lp); noCardDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); noCardDialog.show();
class NoCardDialog extends Dialog { private ImageView iv1; private ImageButton ib1; public NoCardDialog(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setCancelable(false);// 设置点击屏幕Dialog不消失 setContentView(R.layout.nobindcard); iv1= (ImageView) findViewById(R.id.nobindcard_iv1); ib1= (ImageButton) findViewById(R.id.nobindcard_ib1); if(mark==1){ iv1.setImageResource(R.mipmap.nobind_topup); }else if(mark==2){ iv1.setImageResource(R.mipmap.nobind_withdrawal); } } }
2.PopupWindow
public class PopMenuView implements OnItemClickListener { private Context context; private PopupWindow popupWindow; private ListView listView; private OnPItemClickListener listener; private LayoutInflater inflater; private int thisPosition; private Handler handler = new Handler(Looper.getMainLooper()){ @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); switch (msg.what) { case 0: if(listener != null) listener.onItemClick(thisPosition); break; case 1: if(listener != null) listener.onDialogDismiss(); break; default: break; } } }; public PopMenuView(Context context) { this.context = context; inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = (View) inflater.inflate(R.layout.searchpopmenu, null); listView = (ListView) view.findViewById(R.id.searchpopmenu_listView); listView.setAdapter(new PopMenuAdapter(context)); listView.setOnItemClickListener(this); popupWindow = new PopupWindow(view, context.getResources() .getDimensionPixelSize(R.dimen.popmenu_width), LayoutParams.WRAP_CONTENT); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popupWindow.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { // TODO Auto-generated method stub handler.sendEmptyMessage(1); } }); }; @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { thisPosition = position; handler.sendEmptyMessage(0); dismiss(); } public void setOnItemClickListener(OnPItemClickListener listener) { this.listener = listener; } public void showAsDropDown(View parent) { popupWindow.showAsDropDown(parent, -10, context.getResources() .getDimensionPixelSize(R.dimen.popmenu_yoff)); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.update(); } public void dismiss() { if (popupWindow.isShowing()) popupWindow.dismiss(); } public interface OnPItemClickListener { public void onItemClick(int index); public void onDialogDismiss(); } }3.设置背景为透明的方法
把PopWindow自定义的layout背景色设置为透明的颜色 <solid android:color="#80000000"/> 前两位为透明度4.7种形式的Android Dialog使用举例
http://www.oschina.net/question/54100_32486
5.Service中弹出Dialog对话框,即全局性对话框
先说具体做法,原因在其后给出:写好Alter功能块后,在alter.show()语句前加入:alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 注:alter为AlertDialog类型对象然后在AndroidManifest.xml中加入权限:<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission> 下面进行简单的解释:如果只在Service中写入常在Activity中使用的创建Alter的代码,运行时是会发生错误的,因为Alter的显示需要依附于一个确定的Activity类。而以上做法就是声明我们要弹出的这个提示框是一个系统的提示框,即全局性质的提示框,所以只要手机处于开机状态,无论它现在处于何种界面之下,只要调用alter.show(),就会弹出提示框来
0 0
- 对话框 PopupWindow 相关
- PopupWindow相关
- 菜单PopupMenu和对话框AlertDialog、进度条对话框PopupWindow用法相关例子和自己写的案例
- android 对话框 popupWindow
- Android阻塞对话框PopupWindow
- Android-PopupWindow弹出对话框
- Android popupwindow弹出对话框
- Dialog&PopupWindow对话框
- Android popupwindow弹出对话框
- 【Android】AlertDialog PopupWindow对话框
- Android阻塞对话框PopupWindow
- PopupWindow完成对话框
- PopupWindow阻塞式对话框
- AlertDialog跟PopupWindow对话框
- Android 对话框之 PopupWindow
- popupwindow相关资料
- android popupwindow相关备忘录
- popupwindow相关知识
- Spring架构详解之Spring设计模式分析之策略模式
- 文章标题
- 自定义View导致的RecyclerView滑动卡顿
- 网络编程:Reactor与Proactor的概念
- 送给曾经浮躁不安的自己。。。。
- 对话框 PopupWindow 相关
- arm平台分类和配置
- HBase参数优化
- postgre按照某列前几位连接并显示
- ModSecurity requires mod_unique_id to be installed. 解决
- jni调试(线程调试env变量问题)
- Qt状态机框架
- MQTT轻量级即时通讯服务器搭建
- 配置环境变量