Material Design Learning Dialog (by the way, the first two days appbarlayout not talk about the part of the mention)

Source: Internet
Author: User

Reprint please indicate the source: Wang 亟亟 's way of Daniel

Continue before the contents of the MD Series, today said dialog, do not know how to turn a few, anyway, this series are finished words to find something else full.

The Dialogs (hint box) is used to prompt the user for some decision, or some additional information needed to complete a task. Dialog can be either a simple answer pattern with cancellation/determination or a complex pattern of custom layouts, such as some text settings or text input.

The official presentation, like this

Dialog contains a title (optional), content, event.

Title: Mainly used for simple description under the selection type. It is optional and can be assigned when needed.

Content: Mainly describes what kind of decision to make.

Event: The main thing is to allow the user to continue the next activity by confirming a specific action.

Of course, dialog, like any other control, has its own size standard and arrangement style.

Here's a little bit of a touch. The outside of the box can close the prompt box , Google's business logic of the event is also standardized, thus "hope" to enhance the unity of the handset manufacturers.

Original address: http://www.google.com/design/spec/components/dialogs.html

Theory of the crackling not much to say, a general understanding of the line, the specific size distribution or need to take the API to read, the following paste example of the effect.

Example wants to show 2 parts to everyone, 1 is a custom dialog, and the other is to back and forth the bar, first say dialog part

How do I use?

Grade:

dependencies {Compile Filetree (dir:' Libs ', include: [' *.jar ']) Testcompile' junit:junit:4.12 'Compile' com.android.support:appcompat-v7:23.2.0 'Compile' com.android.support:design:23.2.0 'Compile' com.android.support:cardview-v7:23.2.0 'Compile' com.mikepenz:iconics-core:[email protected] 'Compile' com.mikepenz:material-design-iconic-typeface:[email protected] 'Compile' com.github.afollestad.material-dialogs:core:[email protected] ') {transitive =true}} Then remember the build configuration in the main module plus allprojects {repositories {jcenter () Maven {URL"Https://jitpack.io"}    }}

Eclipse's words ......

This package is more dependent than the usual library, but, what com.android.support:cardview com.android.support:design else to use is also OK.

This part of the implementation is not detailed, but is based on Https://github.com/afollestad/material-dialogs rewrite, the library is also very powerful, we can learn to look under.

Because this is a pure diaolg, not those custom controls do not need to put in the XML and then hide all the Java code implementation, direct paste Mainactivity

Key Setup Step code has been written, a look at it, and a few did not put in the I say

.withIconAnimation(false)  //设置ICON出现时是否有动画.setHeaderColor(R.color.dialog_header)  //设置Header颜色,例子设置的是图片.setCancelable(false)  //设置外部点击是否消失
 Public  class mainactivity extends appcompatactivity {Toolbar Toolbar;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        toolbar = (toolbar) Findviewbyid (R.id.toolbar); Setsupportactionbar (toolbar);//Build Dialog Objects        FinalMaterialstyleddialog dialogheader_1 =NewMaterialstyleddialog (mainactivity. This)//Set upper header as Picture. setheaderdrawable (R.drawable.flash)//Set the icon in the middle of the header, or do not set. SetIcon (NewIconicsdrawable (mainactivity. This). Icon (MaterialDesignIconic.Icon.gmi_github). Color (Color.White))//settings appear animation. Withdialoganimation (true)//Set title. Settitle ("I'm title!.")//Set specific text information. SetDescription ("I am a text content")//Set Confirmation button and add callback. setpositive ("OK",NewMaterialdialog.singlebuttoncallback () {@Override                     Public void OnClick(Materialdialog dialog, dialogaction which)                    {Dialog.dismiss (); }                })//Set Cancel button to add callback. setnegative ("Cancel",NewMaterialdialog.singlebuttoncallback () {@Override                     Public void OnClick(Materialdialog dialog, dialogaction which)                    {Dialog.dismiss ();        }}). Build ();        CardView dialogheaderview_1 = (cardview) Findviewbyid (r.id.dialog_1); Dialogheaderview_1.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View view)            {dialogheader_1.show ();    }        }); }}

Let's talk about Appbarlayout.

First of all, how to achieve the effect

1.CoordinatorLayout Wrap Appbarlayout

2. The view of the top area is placed inside the Appbarlayout

3. The view inside the Appbarlayout, controlled by the App:layout_scrollflags attribute, the performance of the scrolling time

In the example isapp:layout_scrollFlags="scroll|exitUntilCollapsed"

Scroll indicates that when scrolling down, the view is scrolled out of the screen until it is hidden.
Enteralways indicates that when scrolling up, the view appears as a scrolling gesture until the original position is restored.

4. Set the property App:layout_behavior on the view that can be scrolled.

In this case, the one.

  <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        xmlns:tools="http://schemas.android.com/tools"        android:layout_width="match_parent"        android:layout_height="match_parent"        app:layout_behavior="@string/appbar_scrolling_view_behavior"        tools:showIn="@layout/activity_main">......

The parent control of our parcel CardView is set to be stretched, and the behavior class is the scrolling behavior that really controls the scrolling time of the view.

In the previous example, we are customizing a behavior (that is, the operation of the. From in our previous Recyleview example) portal http://blog.csdn.net/ddwhan0123/article/details/50825521

Source Address: Https://github.com/ddwhan0123/BlogSample/blob/master/MaterialDesignDialog.zip

Material Design Learning Dialog (by the way, the first two days appbarlayout not talk about the part of the mention)

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.