Android UI component (2)-Windows-like dialog box, androidui

Source: Internet
Author: User

Android UI component (2)-Windows-like dialog box, androidui

Android UI component (2)-Windows-like dialog box


Before starting this chapter, I would like to wish you a happy Mid-Autumn Festival. I believe that many of my friends at work will be given three days off!

If you have time, go home and accompany your parents! The tree is quiet, and the child is not waiting for it! Lucky!

Now let's talk about the truth and the plain language. Today we have prepared a dialog box that imitates the Windows style!


:

I believe that most AlertDialog statements look like the following:



The following dialog box is displayed:



Compare the two types of dialog boxes. From the user's perspective, I believe you prefer the second type of dialog box with clear colors.

Now let's begin to explain how to create a dialog box that imitates the windows style!




The logical process of the Code:

In fact, it is just the layout of the custom dialog box, loading and processing corresponding events!




Core code analysis:

① Button clicking effect: btnexit_selctor.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" >    <item android:state_pressed="false" android:drawable="@drawable/btnexit"/><item android:state_pressed="true" android:drawable="@drawable/btnexit_s"/></selector>



② Layout file of the dialog box: dialog_win.xml

<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id/RelativeLayout1" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <RelativeLayout android: id = "@ + id/titlelayout" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_alignParentLeft = "true" android: layout_alignParentTop = "true" android: background = "#53CC66" android: padding = "5dp"> <TextView android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = "prompt" android: textColor = "# ffffff" android: textSize = "15sp"/> <ImageButton android: id = "@ + id/btncancle" android: layout_width = "30dp" android: layout_height = "30dp" android: background = "@ drawable/btnexit_selctor" android: layout_alignParentRight = "true"/> </RelativeLayout> <LinearLayout android: id = "@ + id/detaillayout" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentLeft = "true" android: layout_below = "@ + id/titlelayout" android: layout_marginLeft = "30dp" android: layout_marginTop = "22dp" android: orientation = "vertical"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_marginLeft = "10dp" android: layout_marginTop = "10dp" android: text = "Windows-like dialog box Demo" android: textColor = "#04 AEDA" android: textSize = "18sp"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_marginLeft = "10dp" android: layout_marginTop = "10dp" android: text = "Author: Coder-pig" android: textColor = "#04 AEDA" android: textSize = "18sp"/> </LinearLayout> <LinearLayout android: layout_marginTop = "30dp" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: orientation = "horizontal" android: layout_below = "@ + id/detaillayout"> <Button android: id = "@ + id/btnblog" android: layout_width = "match_parent" android: layout_height = "40dp" android: background = "@ drawable/btnpress_selctor" android: text = "Access blog" android: layout_margin = "5dp" android: layout_weight = "1" android: textColor = "# ffffff" android: textSize = "20sp"/> <Button android: id = "@ + id/btnclose" android: layout_width = "match_parent" android: layout_height = "40dp" android: background = "@ drawable/btnpress_selctor" android: text = "disabled" android: layout_margin = "5dp" android: layout_weight = "1" android: textColor = "# ffffff" android: textSize = "20sp"/> </LinearLayout> </RelativeLayout>



③ MainActivity. java

Package com. jay. example. windowsdialogdemo; import android. app. activity; import android. app. alertDialog; import android. app. alertDialog. builder; import android. content. context; import android. content. intent; import android.net. uri; import android. OS. bundle; import android. view. layoutInflater; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. imageButton; import android. widget. toast; public class MainActivity extends Activity {private Button btnshow; private View dialogView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); btnshow = (Button) findViewById (R. id. btnshow); btnshow. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {Builder builder = myBuilder (MainActivity. this); final AlertDialog dialog = builder. show (); // click the outside of the screen. The dialog box does not disappear. If it is not set, the dialog box that is clicked outside disappears. setCanceledOnTouchOutside (false); // click the three buttons in the listener dialog box: // ① close the dialog box: ImageButton imgcancle = (ImageButton) dialogView. findViewById (R. id. btncancle); imgcancle. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {dialog. dismiss () ;}}); // ① Button linked to the blog: Button btnblob = (Button) dialogView. findViewById (R. id. btnblog); btnblob. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {Toast. makeText (getApplicationContext (), "Access blog", Toast. LENGTH_SHORT ). show (); Uri uri = Uri. parse ("http://blog.csdn.net/coder_pig"); Intent intent = new Intent (Intent. ACTION_VIEW, uri); startActivity (intent); dialog. dismiss () ;}}); // ③ click the exit Button: Button btnclose = (Button) dialogView. findViewById (R. id. btnclose); btnclose. setOnClickListener (new OnClickListener () {public void onClick (View v) {dialog. dismiss () ;}}) ;}// defines a method for returning the Builder object. In fact, this is the method for setting the view content in the dialog box. private Builder myBuilder (Context context) {final LayoutInflater inflater = MainActivity. this. getLayoutInflater (); AlertDialog. builder builder = new AlertDialog. builder (context); dialogView = inflater. inflate (R. layout. dialog_win, null); return builder. setView (dialogView );}});}}



Download instance code:

Http://pan.baidu.com/s/1jGone5o
















I got your android-22_r01-windows, but the following dialog box appeared when I clicked. What should I do?

I have never tried this .. But have you installed java?

How can I implement a UI component such as Android? Is there any video tutorial or implementation document instance?

It is not necessary to use ListView.

ListView is used in the same style of each Item, and the number of items is not fixed, and needs to be dynamically read

This type of page is a relatively static page. items are fixed and directly implemented using LinearLayout. Each column is a LinearLayout with the left-side ImageView nested, two textviews in the middle, and an arrow on the right.
Set the background image in sequence.

Related Article

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.