根据网上的例子做了一些修改
1.
DialogActivity.java
/** * 弹出Activity * 调用案例 Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.zl); Intent intent = new Intent(); intent.putExtra("src", bm); intent.setClass(MainActivity.this,DialogActivity.class); startActivity(intent); * */ public class DialogActivity extends Activity { private LinearLayout layout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(R.style.Transparent); setContentView(R.layout.dailog); //获取参数 Intent intent = getIntent(); Bitmap bm = (Bitmap) intent.getExtras().get("src"); ImageView imageView = (ImageView)findViewById(R.id.myImage); imageView.setImageBitmap(bm); // ImageButton imageButton = (ImageButton)findViewById(R.id.ibtnClose); // //imageButton.setImageResource(); // imageButton.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // DialogActivity.this.finish(); // } // }); layout=(LinearLayout)findViewById(R.id.layout); layout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub DialogActivity.this.finish(); } }); } @Override public boolean onTouchEvent(MotionEvent event){ finish(); return true; } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <LinearLayout android:id="@+id/layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical"> <ImageView android:id="@+id/myImage" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/btn_img1" /> </LinearLayout> </LinearLayout>
3.styles.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Transparent"> <item name="android:windowBackground">@color/transparent_background</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item> </style> <color name="transparent_background">#50000000</color> </resources>