Android Imitation iOS dialog box is packaged as a tool class

Source: Internet
Author: User

Dialog in Android is a very common way to prompt users, but a lot of products dogs call us to do Android imitation iOS, engage in our Android programmer very hard, with what effect is always imitation of iOS, there is no feelings, But iOS in the interface package is really much better than Android, Spit groove complete, such as a very common scenario is to prompt the user in the case of no net, see:


In a lot of the interface to have a hint, then naturally think of the package, and not in every page to rewrite a piece, say no more directly on the code

Commondialog.java

public class CommonDialog extends dialog{private context context; private String title; Private Clicklistenerinterface Clicklistenerinterface;public CommonDialog (context context) {Super (context, R.style.mydialogstyle); this.context = context;}         @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);    Init (); } private void Init () {Layoutinflater inflater =layoutinflater.from (context); View View =inflater.inflate (R.layout.dialog_common, null); Setcontentview (view);        TextView tv_ok= (TextView) View.findviewbyid (R.ID.TV_OK); Tv_ok.setonclicklistener (new Clicklistener ());        Window Dialogwindow = GetWindow ();        Windowmanager.layoutparams LP = Dialogwindow.getattributes (); Displaymetrics d = context.getresources (). Getdisplaymetrics (); Get screen width, height with lp.width = (int) (D.widthpixels * 0.8); The height is set to the screen of the 0.6 dialogwindow.setattributes (LP);} Public interface Clicklistenerinterface {public void doconfirm (); } public void Setclicklistener (Clicklistenerinterface clicklistenerinterface) {this.clicklistenerinterface = cl     Icklistenerinterface;              } Private class Clicklistener implements View.onclicklistener {@Override public void OnClick (View v) {            int id = V.getid ();                Switch (ID) {case r.id.tv_ok:dismiss ();            Break }         }     };}

Dialog_common.xml

<?xml version= "1.0" encoding= "UTF-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/     Android "android:id=" @+id/dialog_layout "android:layout_width=" wrap_content "android:layout_height=" Wrap_content " android:background= "@drawable/login_bg" android:gravity= "center_horizontal" android:orientation= "vertical" a ndroid:layout_marginbottom= "10DP" > <textview android:layout_width= "wrap_content" android:layout _height= "Wrap_content" android:layout_margintop= "1DP" android:gravity= "Center_horizontal" Android:pad ding= "10DP" android:text= "warm Tip" android:textcolor= "@color/c282828" android:textsize= "18SP"/><t    Extview android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "Request timed out, please determine if the network is healthy"        Android:textsize= "15SP" android:textcolor= "#383838"/><view android:layout_width= "Match_parent"    android:layout_height= "0.4DP"    android:background= "@color/line_color01" android:layout_margintop= "10DP"/><textview android: Id= "@+id/tv_ok" android:layout_width= "fill_parent" android:layout_height= "30DP" android:text= "OK" android:text Size= "16sp" android:layout_margintop= "10DP" android:layout_marginbottom= "10DP" android:focusable= "true" Androi D:clickable= "true" android:gravity= "center" android:textcolor= "#00B2EE"/></linearlayout>

Dialog Styles Style

<style name= "Mydialogstyle" >        <item name= "Android:windowbackground" > @android: Color/transparent </item>        <item name= "Android:windowframe" > @null </item>        <item name= "Android: Windownotitle ">true</item>        <item name=" android:windowisfloating ">true</item>        < Item Name= "Android:windowistranslucent" >true</item>        <item name= "Android:windowcontentoverlay" > @null </item>        <item name= "Android:windowanimationstyle" > @android: style/animation.dialog</ item>        <item name= "android:backgrounddimenabled" >true</item>    </style>
Use:

Final CommonDialog confirmdialog = new CommonDialog (getactivity ());
confirmdialog.show ();
Confirmdialog.setclicklistener (New Commondialog.clicklistenerinterface () {
@Override
public void Doconfirm () {}
});

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Imitation iOS dialog box is packaged as a tool class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.