Android phase 33rd-Dialog application

Source: Internet
Author: User

Today, there is a big problem, oh, but there is a glance at Daniel, and then solved, Alertdialog and dialog custom after the fillet of processing, if you and I do not see the details of the words are planted, with the alertdialog can not make the round corner of the background transparent, So you have to deal with Dialog, that is, the following method.

Dialog:

private static dialog mdialog;//  the XML method that loads the item in the GridView public static view  GetView (Context context, int layoutid)  {LayoutInflater inflater =  ( Layoutinflater)  context.getsystemservice (Context.layout_inflater_service); View layout = inflater.inflate (layoutid, null); return layout;} /** *  Display custom dialog box  *  *  @param  context *  @param  message *   @param  listener */public static void showdialog (final context context ,  string message,final ialertdialogbuttonlistener listener)  {View dialogView  = null;// dialog.builder builder = new builder (context,//  r.style.theme_transparent); Mdialog = new dialog (context, r.style.theme_transparent); Dialogview = getview (Context, r.layout.dialog_view); Button btn_ok =  (Button)  dialogview.findviewbyid (R.ID.BTN_OK); button btn_cancel =  (Button)  dialogview.findviewbyid (r.id.btn_cancel); textview txt_dailog_message =  (TextView)  dialogview.findviewbyid (r.id.txt_dailog_message); Txt_dailog_message.settext (message); Btn_ok.setonclicklistener (New view.onclicklistener ()  {@ Overridepublic void onclick (view arg0)  {//  close dialogif  (mdialog != null )  {mdialog.cancel ();}   Event Callback if  (Listener != null)  {listener.onclick ();}   Play Sound// myplayer.playtone (Context, myplayer.index_stone_enter);}); Btn_cancel.setonclicklistener (New view.onclicklistener ()  {@Overridepublic  void onclick ( VIEW ARG0)  {//  close dialogif  (mdialog != null)  {mdialog.cancel ();}   Play Sound// myplayer.playtone (Context, myplayer.index_stone_cancel);}); /  set View// builder.setview (Dialogview) for dialog; MdiaLog.setcontentview (Dialogview);// mdialog = builder.create (); Mdialog.show ();}} 

    alertdialog:

/** *  Display custom dialog box  *  *  @param  context *  @param  message *   @param  listener */public static void showdialog (final context context ,  string message,final ialertdialogbuttonlistener listener)  {View dialogView  = null; Alertdialog.builder builder = new builder (context,r.style.theme_transparent);d Ialogview  = getview (Context, r.layout.dialog_view);imagebutton btn_ok =  (ImageButton)  dialogview.findviewbyid (R.ID.BTN_OK);imagebutton btn_cancel =  (ImageButton)   Dialogview.findviewbyid (R.id.btn_cancel); textview txt_dailog_message =  (TextView)  dialogview.findviewbyid (r.id.txt_dailog_message); Txt_dailog_message.settext (message); Btn_ok.setonclicklistener (New view.onclicklistener ()  {@ Overridepublic void onclick (view arg0)  {//  close dialogif  (malertDialog != null)  {malertdialog.cancel ();}   Event Callback if  (Listener != null)  {listener.onclick ();}   Play Sound Myplayer.playtone (Context, myplayer.index_stone_enter);}); Btn_cancel.setonclicklistener (New view.onclicklistener ()  {@Overridepublic  void onclick ( VIEW ARG0)  {//  close dialogif  (malertdialog != null)  {malertdialog.cancel ();}   Play Sound Myplayer.playtone (Context, myplayer.index_stone_cancel);}); /  set Viewbuilder.setview (Dialogview) for Dialog; Malertdialog = builder.create (); MAlertDialog.show ();}

Af_dialog_background fillet:

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <solid android:color= "#3C4856"/> <corners android:bottomleftradius= "0.1DP" Android:bottom rightradius= "0.1DP" android:topleftradius= "10DP" android:toprightradius= "10DP"/></shape>

Dialog_view:

<?xml version= "1.0"  encoding= "Utf-8"? ><linearlayout xmlns:android= "http// Schemas.android.com/apk/res/android "    android:layout_width=" Fill_parent "     android:layout_height= "Wrap_content"     android:gravity= "Center_horizontal"     android:orientation= "vertical"     android:paddingleft= "10DP"      android:paddingright= "10DP"  >    <LinearLayout         android:layout_width= "Match_parent"          android:layout_height= "Wrap_content"         android: background= "@drawable/af_dialog_background"         android:orientation = "Vertical"  >        <TextView             style= "@style/textviewstyle_aboutus"              Android:layout_gravity= "left"             android: layout_marginleft= "10DP"             android:layout _margintop= "5DP"             android:text= "@string/ Af_logo_10_dialog_title "            android: Textcolor= "@color/white4"             android: Textsize= "14SP"  />        <ScrollView             android:layout_width= "Wrap_content"              android:layout_height= "Wrap_content"              android:layout_marginleft= "10DP"              android:layout_marginright= "10DP"              android:layout_margintop= "10DP"              android:background= "@drawable/af_dialog_background"              android:fillviewport= "true"              android:scrollbars= "None"  >             <TextView                 android:id= "@+id/txt_dailog_message"                  style= "@style/textviewstyle_aboutus"                  android:linespacingmultiplier= "1.2"                  android:text= "@string/af_logo_10_dialog_content"                 android: Textcolor= "@color/white4"                  android:textsize= "14SP"  />        </scrollview >    </LinearLayout>    <LinearLayout         android:layout_width= "Match_parent"          android:layout_height= "Wrap_content"         android:background= " @color/white "        android:gravity=" Center_horizontal "         android:orientation= "Horizontal"  >        <button             android:id= "@+id/btn_cancel"              style= "? Android:attr/buttonbarbuttonstyle"             android:layout_width= "0DP"              android:layout_height= "Wrap_content"              android:layout_marginbottom= "5DP"              android:layout_marginleft= "25DP"              android:layout_marginright= "15DP"              android:layout_margintop= "5DP"               android:layout_weight= "1"              android:background= "@drawable/btn_cancelclick"              android:contentdescription= "@string/action_settings"              android:paddingbottom= "8DP"              android:paddingtop= "8DP"              android:text= "@string/af_cancel"              android:textcolor= "@color/white"              Android:textsize= "16SP"  />        <Button             android:id= "@+id/btn_ok"           &nbSp;  style= "Android:attr/buttonbarbuttonstyle"              android:layout_width= "0DP"              android:layout_height= "Wrap_content"              android:layout_marginbottom= "5DP"              android:layout_marginleft= "15DP"              android:layout_marginright= "25DP"              android:layout_margintop= "5DP"              android:layout_weight= "1"             android: background= "@drawable/btn_able"             android : contentdescription= "@string/actioN_settings "            android:paddingbottom=" 8DP "             android:paddingtop= "8DP"              android:text= "@string/af_confirm"              android:textcolor= "@color/white"              android:textsize= "16SP"  />     </LinearLayout></LinearLayout>

     Last is style:

<style name= "Theme_transparent"  parent= "@android: Style/theme.dialog" >         <item name= "Android:windowframe" > @null </item>         <item name= "Android:windowisfloating" >true</item>         <item name= "Android:windowistranslucent" >true</item>         <item name= "Android:windownotitle" >true</item>         <item name= "Android:background" > @android: color/ Transparent</item>        <item name= "Android: Windowbackground "> @android:color/transparent</item>         <item name= "Android:backgrounddimenabled" >true</item>         <item name= "Android:bacKgrounddimamount ">0.6</item>    </style> 

Thank you Hongyang big God ~ ~ Happy to make money every day

This article is from the "Liangxiao Technology Center" blog, please be sure to keep this source http://liangxiao.blog.51cto.com/3626612/1613291

Android phase 33rd-Dialog application

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.