下看一下效果图
%title插图%num %title插图%num

点击TextView弹出Dialog
点击图片Dialog消失

先看一下MainActivity

package com.cxy.demo;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import startdialogimageview.qq986945193.dialogdemo.R;

/**
*程序功能:Dialog显示图片
*/
public class MainActivity extends Activity {

Dialog dia;
private TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv = (TextView) findViewById(R.id.tv);
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dia.show();
}
});

Context context = MainActivity.this;
dia = new Dialog(context, R.style.edit_AlertDialog_style);
dia.setContentView(R.layout.activity_start_dialog);
ImageView imageView = (ImageView) dia.findViewById(R.id.start_img);
imageView.setBackgroundResource(R.mipmap.iv_android);
//选择true的话点击其他地方可以使dialog消失,为false的话不会消失
dia.setCanceledOnTouchOutside(true); // Sets whether this dialog is
Window w = dia.getWindow();
WindowManager.LayoutParams lp = w.getAttributes();
lp.x = 0;
lp.y = 40;
dia.onWindowAttributesChanged(lp);
imageView.setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View view) {
dia.dismiss();
}
});
}

}

用到的style

<style name=”edit_AlertDialog_style” parent=”@android:style/Theme.Dialog”>
<item name=”android:windowIsFloating”>true</item>
<item name=”android:windowIsTranslucent”>true</item>
<item name=”android:windowNoTitle”>true</item>
<!– 是否启用标题栏 –>
<item name=”android:windowBackground”>@android:color/transparent</item>
<item name=”android:background”>@android:color/transparent</item>
<item name=”android:backgroundDimEnabled”>true</item>
<!– 是否使用背景半透明 –>
</style>

布局文件的话就不上传了,比较简单。