Objective
Android often use dialog to implement some hints and some special effects, and the style is not the same, each time have to look up a lot of information, it is not necessarily able to solve. dialog box is a good thing to create a simple and practical. In the current development, many developers prefer to use the activity instead of the dialog, at least the author's team, similar to the upgrade prompts or instructions page and other places of interaction, a large number of dialog to replace the activity, the benefits are obvious, Activity has a more flexible operation and layout, in addition, it is important to note that some code that is easily involved in memory leaks is better executed in activity than in dialog, of course, this is the author's own point of view, the article has the wrong place, you are welcome to make corrections, so that the author in time to correct and learn together.
First up Effect chart:
Implementation methods
This dialog box can often be encountered in some apps, first in the layout:
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/" Android "xmlns:tools=" Http://schemas.android.com/tools "android:id=" @+id/activity_main "android:layout_width="
300DP "android:layout_height=" 400DP "android:layout_gravity=" center "android:background=" @drawable/popup_bg " android:orientation= "vertical" tools:context= "com.yankee.september_2.MainActivity" > <linearlayout android: Layout_width= "Match_parent" android:layout_height= "wrap_content" android:layout_above= "@+id/btn_update" Android: Layout_marginbottom= "24DP" android:layout_marginleft= "20DP" android:layout_marginright= "20DP" android:orientation = "vertical" > <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:l Ayout_gravity= "Center_horizontal" android:text= "Version" android:textcolor= "#53BAF8" android:textsize= "14SP"/>
; <scrollview android:layout_width= "Match_parent" android:layout_height= "100DP" android:layout_gravity= "Center_horizontal" android:layout_margintop= "12DP" > <T Extview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text=, when It comes to the issues of a, individuals ' opinions vary from person to person. Some people believe that robots would enlighten our life while the other are worried about that they would ruin the whole world 。 As I, the increasing number of the has to alter everything the coming future entirely. "Android:textcolor=" #404040 "android:textsize=" 12sp "/> </ScrollView> </LinearLayout> <butt On android:id= "@+id/btn_update" android:layout_width= "130DP" android:layout_height= "32DP" Android:layout_alignpare Ntbottom= "true" android:layout_centerhorizontal= "true" android:layout_marginbottom= "16DP" android:background= "@ Color/coloraccent "android:gravity=" "Center" android:text= "Update Now" AndroId:textcolor= "#FFFFFF" android:textsize= "14sp"/> </RelativeLayout>
The layout code should be noted that the size of this layout is written dead, because from the code can be seen, dialog box hollowing effect is actually a background image produced, hard art but cool programmer.
Step two: Then the operation of the manifest file, the corresponding activity theme set to the custom theme, the background is transparent, remove the title, note that this topic inherits from the dialog box theme.
Manifest
<activity
android:name= ". Mainactivity "
android:screenorientation=" Portrait "
android:theme=" @style/tipdialog ">
</ Activity>
Styles.xml:
<style name= "Tipdialog" parent= "@android: Style/theme.dialog" >
<item name= "Android:windownotitle" > true</item>
<item name= "Android:windowbackground" > @android:color/transparent</item>
</style>
Finally, there is no final, there is a point, that is, let the current activity to inherit from the activity, rather than appcompatactivity, otherwise will report the subject error.
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.