activity just show a dialog
activity只显示dialog 只显示dialog的activity
Activity_Just_Show_A_Dialog.java
public class Activity_Just_Show_A_Dialog extends Activity {
private final static int PHONE = 1;
AlertDialog.Builder builder;
Dialog dialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //can't omit this line
//set this activity's window not be seen
Window win = getWindow();
win.setLayout(0, 0);
showDialog(PHONE);
dialog.setOnDismissListener(listenDialogDismissed);
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch(id) {
case PHONE:
builder = new AlertDialog.Builder(this);
builder.setTitle("this is a Dialog");
dialog = builder.create();
break;
default:
break;
}
return dialog;
// return super.onCreateDialog(id);
}
public OnDismissListener listenDialogDismissed = new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
// TODO Auto-generated method stub
//end this activity, so it looks like there is no activity, just a dialog has showed
finish();
}
};
}
main.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!-- android:visibility="invisible" -->
3 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 >
7
8
9 </LinearLayout>
AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.hua.Activity_with_dialog"
4 android:versionCode="1"
5 android:versionName="1.0">
6 <application android:icon="@drawable/icon" android:label="@string/app_name">
7 <activity android:name=".Activity_Just_Show_A_Dialog"
8 android:theme="@android:style/Theme.Dialog"
9 android:label="@string/app_name">
10 <intent-filter>
11 <action android:name="android.intent.action.MAIN" />
12 <category android:name="android.intent.category.LAUNCHER" />
13 </intent-filter>
14 </activity>
15
16 </application>
17
18
19 </manifest>
浙公网安备 33010602011771号