Android Advanced Alertdialog Customization

Source: Internet
Author: User

There are many ways to customize Alertdialog, and here are two ways to do it.

The first is simpler, only custom content.

The following six ways of using are described in detail in the Alertdialog use.

Simple Alertdialog (only a simple piece of information, such as about us)

Second, with the button Alertdialog (Display prompt information, let the user action, such as exit warning box)

Third, similar to the ListView Alertdialog (display content, such as some of the registration information of someone)

Four, similar to RadioButton Alertdialog (let the user choose, select)

V. Alertdialog of similar checkbox (allows users to select multiple)

VI, custom view of the Alertdialog (when the above methods can not meet your needs, it is necessary to customize)

The final sixth is the implementation of the custom content, such as want to do a login dialog box, in the first five ways obviously can not be achieved.

At this time , through Alertdialog.builder's Setview to set their own definition of the login interface,

While the title and buttons are also native to Android, if you are custom like this way, please go to the previous link to view the last way.

The second approach is described here.

First look at the effect, the left is the native Alertdialog, the right is the custom alertdialog, so the custom is mainly to make the interface more unified.

The code is as follows:

String info = citydata.getpointerlist (). get (position). ToString (); Alertdialog Alertdialog = new Alertdialog.builder (cityactivity.this). Create (); Alertdialog.show (); window window = Alertdialog.getwindow (); Window.setcontentview (R.layout.dialog_main_info); TextView Tv_title = (TextView) Window.findviewbyid (r.id.tv_dialog_title); Tv_title.settext ("More Information"); TextView tv_message = (TextView) Window.findviewbyid (r.id.tv_dialog_message); Tv_message.settext (info);

Layout file:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android: Background= "#ffff"    android:orientation= "vertical" >    <textview        android:id= "@+id/tv_dialog_ Title "        android:layout_width=" match_parent "        android:layout_height=" wrap_content "        android:background = "#7a7"        android:padding= "8DP"        android:textcolor= "#eee"        android:textsize= "20sp"        android: textstyle= "Bold"/>    <textview        android:id= "@+id/tv_dialog_message"        android:layout_width= " Wrap_content "        android:layout_height=" wrap_content "        android:layout_margin=" 5DP "        android:padding= "3DP"/></linearlayout>


In fact, the main purpose of the custom here is to make the title background color green, and the activity of the background green consistent, more harmonious.

Alertdialog is a subclass of dialog, and can also be customized directly based on dialog. There are a lot of ways to try again.

jason0539

Weibo: http://weibo.com/2553717707

Blog:http://blog.csdn.net/jason0539(reprint please indicate the source)

Android Advanced Alertdialog Customization

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.