To see the effect first, there is a perceptual understanding.
The middle hint is actually an activity, OK, here's a step-by-step implementation of this magical effect.
The first step: Design Dialog Page Activity_simulate_dialog.xml
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http ://schemas.android.com/apk/res/android " android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:layout_gravity= "center" android:gravity= "Center_horizontal" android:background= "#ffffff" > <LinearLayout android:layout_width= " Wrap_content " android:layout_height=" Wrap_content " android:layout_gravity= "Center_horizontal"
android:orientation= "Vertical" > &nbSp <TextView android:id= "@+id/tv_title" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "hint" /> <TextView android:id= "@+id/tv_content" android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:text= "Are you sure you want to buy the movie tickets?" " /> <LinearLayout android:layout_width= "200DP" android:layout_height= " 80DP " android:gravity=" Center " android:orientation = "Horizontal" > <Button android:id= "@+id/btn_cancel" anDroid:layout_width= "100DP" android:layout_height= "40DP"
android:text= "Cancel" /> <Button android:id= "@+id/btn_ Confirm " android:layout_width= "100DP" android:layout_height= "40DP"
android:text= "Confirmation" /> </LinearLayout> </LinearLayout> </RelativeLayout>
Step Two: Write a pop-up window activity Simulatedialogactivity.java
ackage com.figo.study; import android.app.activity; import android.os.bundle; import android.view.motionevent; import android.view.View; import android.view.view.onclicklistener; import android.widget.button;
public class simulatedialogactivity extends activity { @Override protected void OnCreate (bundle savedinstancestate) { // TODO Auto-generated method stub super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_simulate_dialog); Button btn_cancel = (Button) findviewbyid (r.id.btn_cancel);
btn_cancel.setonclicklistener (New onclicklistener () { @Override public void onclick (VIEW&NBSP;V) { Finish (); }  }); Button btn_confirm = (Button) findviewbyid (r.id.btn_confirm); btn_confirm.setonclicklistener (New OnClickListener ( ) { @Override public void onclick (VIEW&NBSP;V) { Finish (); }  }); }
//Click External area to close the activity @Override public boolean ontouchevent (motionevent event) { finish (); return true; } }
step three: Style.xml design style
<item name= "Android:windowbackground" > @android: Color/transparent</item > <item name= "Android:windowistranslucent" >true</item> <item name= "Android:windownotitle" >true</item> <item name= "Android:windowanimationstyle" > @style/anim_scale</item > </style> <style name= "Anim_scale" parent= "@android: style/ Animation.activity "> <item name=" Android: Activityopenenteranimation "> @anim/scale_in</item> <item Name= "Android:activityopenexitanimation" > @anim/scale_out</item> <item name= "Android:activitycloseenteranimation" > @anim/scale_in</item> <item name= "Android:actIvitycloseexitanimation "> @anim/scale_out</item>
Step Fourth: Anim folder design animation
page into animation scale_in.xml
<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android= "http://" Schemas.android.com/apk/res/android " > <scale android:fromxscale= "1.0" android:interpolator= "@android: Anim/accelerate_decelerate_interpolator" android:toxscale= "1.0" android:fromyscale= "0.0" android:toyscale= "1.0" android:duration = " " android:pivotx= "0" android:pivoty= "10%" /> &nbsP </set>
Face exit animation Scale_out.xml
<?xml version= "1.0" encoding= "Utf-8"?> <set xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<scale
android:fromxscale=" 1.0 "
android:interpolator=" @android: Anim/accelerate_ Decelerate_interpolator "
android:toxscale=" 1.0 "
android:fromyscale=" 1.0 "
android:toyscale=" 0.0 "
android:duration="
android:pivotx= "0"
android:pivoty= "10%"
/>
</set>
Fifth step: A key step in the Androidmanifest.xml Registration Simulation dialog box activity
<activity
android:name= "com.figo.study.SimulateDialogActivity"
android:label= "@string/app_n Ame "
android:theme=" @style/simulatedialog ">
</activity>
Step Sixth: Invoke dialog box activity
Button Btndialog = (button) Findviewbyid (R.id.btn_dialog);
Btndialog.setonclicklistener (New Onclicklistener () {
@Override public
void OnClick (Vie W v) {
Intent Intent = new Intent (testactivity.this, Simulatedialogactivity.class);
startactivity (Intent);
}
});
Set up the Android activity as a dialog-box
To set the activity as a dialog style, simply add the following code to the activity attribute:
Android:theme= "@android: Style/theme.dialog"
You can then add a small picture to the left of the activity to make it more like dialog, the code is as follows:
package com.home.testactivitydialog; import android.os.bundle; import android.view.window; import android.app.activity; Public class MainActivity extends Activity { @Override protected void oncreate (bundle savedinstancestate) { super.oncreate ( savedinstancestate); requestwindowfeature ( Window.feature_left_icon); settitle ("Test dialog type activity ");// set title setcontentview (R.layout.main); Set layout content // set left icon getwIndow (). Setfeaturedrawableresource (window.feature_left_icon, android. R.drawable.ic_dialog_alert); } }
However, the above settings often do not meet the actual requirements, because the appearance, background, and some properties used by default, the following use style to customize one, can be changed to the actual needs of the future:
<style name= "Dialog" parent= "@android: Style/theme.dialog" > <!-- Go to black side --> <item name= "Android: Windowframe "> @null </item> <!-- setting can slide -->
<item name= "android:windowisfloating" >true</item> <!-- setting is transparent --> <item name= "Android:windowistranslucent" >true</item> <!-- Untitled -- > <item name= "Android:windownotitle" >true</item> <!-- background --> <item Name= "Android:background" > @null </item> <!-- window background -- > &nbsP <item name= "Android:windowbackground" > @android: Color/transparent</item > <!-- dimming --> < Item name= "android:backgrounddimenabled" >false</item> <!-- Click on the blank part activity does not disappear --> <item name= "Android: Windowcloseontouchoutside ">false</item> </style>
This is directly referenced in the topic:
android:theme= "@style/dialog" &NBSP;
Click the activity margin to not disappear also can be set inside the code, In the OnCreate () method, add the following:
Setfinishontouchoutside (false);