标签:
1、实现效果
点击头像 弹出全屏dialog,长按图片弹出“保存图片对话框”,短按dialog消失。
package com.example.widget; import android.app.Dialog; import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnLongClickListener; import android.widget.ImageView; import com.kuangren.real.R; import com.will.ui.view.ChatDialog; public class HeadDialog extends Dialog { private ImageView imageView; Context context; private Bitmap bitmap; public HeadDialog(Context context) { super(context); // TODO Auto-generated constructor stub this.context = context; } public HeadDialog(Context context, int theme) { super(context, theme); this.context = context; } private ChatDialog alertDialog; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.setContentView(R.layout.head_dialog); imageView = (ImageView) findViewById(R.id.dialog_head); if(bitmap!=null){ imageView.setImageBitmap(bitmap); } // 这里要写全, imageView.setOnClickListener(new android.view.View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub HeadDialog.this.dismiss(); } }); imageView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { // TODO Auto-generated method stub alertDialog.show(); return false; } }); } public ImageView getImageView() { return imageView; } public ChatDialog getAlertDialog() { return alertDialog; } public void setAlertDialog(ChatDialog alertDialog) { this.alertDialog = alertDialog; } public Bitmap getBitmap() { return bitmap; } public HeadDialog setBitmap(Bitmap bitmap) { this.bitmap = bitmap; return this; } }
调用
HeadDialog dialog =new dialog.setAlertDialog(alertDialog); dialog.setBitmap(bitmap).show();
注意:
android.view.View.OnClickListener与content.DialogInterface.OnClickListener()冲突
使用时带上全路径
标签:
原文地址:http://www.cnblogs.com/xingyyy/p/4278942.html