首先,設置要覆蓋在最上方的dialog的view
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout Android:background="@drawable/navigater_bg" android:padding="0.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <ImageView android:id="@id/ivNavigater_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/navigater_top" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" />
- <ImageView android:id="@id/ivNavigater_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/navigater_center" android:layout_centerInParent="true" />
- <ImageView android:id="@id/ivNavigater_clickable" android:padding="0.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="0.0dip" android:src="@drawable/navigater_clickable" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" />
- <ImageView android:id="@id/ivNavigater_bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="0.0dip" android:src="@drawable/navigater_bottom" android:adjustViewBounds="true" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" />
- </RelativeLayout>
然後,在values/styles.xml添加style for 半透明:
- <style name="Dialog_Fullscreen">
- <item name="android:windowBackground">@android:color/transparent</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowContentOverlay">@null</item>
- <item name="android:windowAnimationStyle">@style/Dialog_Anim</item>
- <item name="android:colorBackgroundCacheHint">@null</item>
- </style>
繼續添加style for 淡入淡出效果:
- <style name="Dialog_Anim">
- <item name="android:windowEnterAnimation">@anim/fading_in</item>
- <item name="android:windowExitAnimation">@anim/fading_out</item>
- </style>
在anim文件夾下,添加文件fading_in.xml for 淡入
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <alpha android:duration="500" android:fromAlpha="0.1" android:toAlpha="1.0" />
- </set>
添加文件fading_out.xml for 淡出
- <?xml version="1.0" encoding="utf-8"?>
- <set
- xmlns:android="http://schemas.android.com/apk/res/android">
- <alpha android:duration="500" android:fromAlpha="0.1" android:toAlpha="1.0" />
- </set>
最後,在要彈出對話框的地方添加如下代碼:
- Dialog dialog = new Dialog(this, R.style.Dialog_Fullscreen);
- dialog.setContentView(R.layout.sina);
- ImageView iv = (ImageView)dialog.findViewById(R.id.ivNavigater_clickable);
- iv.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- dialog.show();
最終效果如圖: