├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── build.gradle ├── example ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── carbs │ │ └── android │ │ └── mddialog │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── carbs │ │ │ └── android │ │ │ └── mddialog │ │ │ └── ActivityMain.java │ └── res │ │ ├── drawable │ │ └── color_cursor.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── content_dialog.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── cn │ └── carbs │ └── android │ └── mddialog │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── carbs │ │ └── android │ │ └── library │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── carbs │ │ │ └── android │ │ │ └── library │ │ │ └── MDDialog.java │ └── res │ │ ├── layout │ │ └── layout_mddialog.xml │ │ └── values │ │ ├── strings.xml │ │ └── values_mddialog.xml │ └── test │ └── java │ └── cn │ └── carbs │ └── android │ └── library │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MDDialog -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MDDialog 2 | 3 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MDDialog-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3822)
4 | * [English](#english) 5 | 6 | ## 前言 7 | `MDDialog`是一款`Material Designed`风格的`Dialog`,可以灵活定制其内容以及显示方式,如:可以添加中间的`ContentView`,可以对`ContentView`自由的添加代码操作,如添加点击事件等等;对于多个选项风格的dialog,提供了直接设置多个选项的功能,并提供了精细的UI按下效果、点击回调函数等等。 8 | 9 | ## 介绍 10 | 这款`Material Designed`风格的`Dialog`的设计灵感来自于MD设计理念,你可以通过使用和`AlertDialog`相似的代码来构建`MDDialog`。 11 | 12 | `MDDialog`具有多种有趣的属性:
13 | 1. 可以设置显示/隐藏title、显示/隐藏 确定/取消按钮(或者同时隐藏两个button,具体UI效果可见微信的选择对话框);
14 | 2. 可以向`MDDialog`添加一个自定义的`View`,同时可以在构建`MDDialog`时,使用`setContentViewOperator(...)`函数,添加操作自定义view的代码;
15 | 3. 可以给`MDDialog`设置`String[] messages`,构建`MDDialog`的`builder`中提供了响应点击每一个`String`的回调函数,即,通过`setOnItemClickListener(...)`设置点击每一条目的回调;
16 | 4. 可以自由定制`MDialog`的四个角的半径大小;
17 | 5. `MDDialog`自动为每个`message`提供了按下效果,且按下效果会随着此`item`是否具有圆角而改变;
18 | 6. 可以通过两种方式设置`MDDialog`的宽度,使用宽度占整个屏幕宽度的比值,或使用是精确的尺寸;
19 |
20 | 21 | ## 截图 22 |
23 | ![you can check the MDDialog_setView.png](https://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setview.png) 24 |

25 |
26 | ![添加message MDDialog_setMessages](https://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setmessages.png) 27 |
28 | 29 | ## 使用 30 | 首先添加依赖 31 | ``` 32 | dependencies { 33 | compile 'cn.carbs.android:MDDialog:1.0.0' 34 | } 35 | ``` 36 | 在`java`代码中构造`MDDialog` 37 | ``` 38 | 可以构建两种不同模式的MDDialog,这两种模式不能够同时使用 39 | 1.为MDDialog设置自定义View: 40 | new MDDialog.Builder(ActivityMain.this) 41 | // .setContentView(customizedView) 42 | .setContentView(R.layout.content_dialog) 43 | .setContentViewOperator(new MDDialog.ContentViewOperator() { 44 | @Override 45 | public void operate(View contentView) {//这里的contentView就是上面代码中传入的自定义的View或者layout资源inflate出来的view 46 | EditText et = (EditText) contentView.findViewById(R.id.edit0); 47 | et.setHint("hint set in operator"); 48 | } 49 | }) 50 | .setTitle("添加") 51 | .setNegativeButton(new View.OnClickListener() { 52 | @Override 53 | public void onClick(View v) { 54 | } 55 | }) 56 | .setPositiveButton(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View v) { 59 | } 60 | }) 61 | .setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() { 62 | @Override 63 | public void onClick(View clickedView, View contentView) { 64 | //这里的contentView就是上面代码中传入的自定义的View或者layout资源inflate出来的view,目的是方便在确定/取消按键中对contentView进行操作,如获取数据等。 65 | EditText et = (EditText) contentView.findViewById(R.id.edit0); 66 | Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show(); 67 | } 68 | }) 69 | .setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() { 70 | @Override 71 | public void onClick(View clickedView, View contentView) { 72 | EditText et = (EditText) contentView.findViewById(R.id.edit1); 73 | Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show(); 74 | } 75 | }) 76 | .setWidthMaxDp(600) 77 | // .setShowTitle(false)//default is true 78 | // .setShowButtons(true)//default is true 79 | .create() 80 | .show(); 81 | 82 | 2.设置 String[] messages,每一个String都将对应一个item,具体可以看效果图 83 | 84 | final String[] messages = new String[]{"两个黄鹂鸣翠柳,一行白鹭上青天。", 85 | "窗含西岭千秋雪,门泊东吴万里船。", 86 | "君不见,黄河之水天上来,奔流到海不复回;君不见,高堂明镜悲白发,朝如青丝暮如雪。"}; 87 | new MDDialog.Builder(ActivityMain.this) 88 | .setMessages(messages) 89 | .setTitle("一首古诗") 90 | .setNegativeButton(new View.OnClickListener() { 91 | @Override 92 | public void onClick(View v) { 93 | } 94 | }) 95 | .setPositiveButton(new View.OnClickListener() { 96 | @Override 97 | public void onClick(View v) { 98 | Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show(); 99 | } 100 | }) 101 | .setOnItemClickListener(new MDDialog.OnItemClickListener() { 102 | @Override 103 | public void onItemClicked(int index) { 104 | Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show(); 105 | } 106 | }) 107 | .setWidthMaxDp(600) 108 | .setShowTitle(false) 109 | .setShowButtons(true) 110 | .create() 111 | .show(); 112 | 113 | ``` 114 | 115 | 116 | #English 117 | 118 | ## Abstract 119 | a material designed style dialog, can add operation of content view, set messages, respond to onclick of messages items and so on 120 | 121 | ## Introduction 122 | the `MDDialog` inspired by the `Material Design` Pattern. You can get a MD style dialog quickly by using `MDDialog Builder`. 123 | this `MDDialog` has many interesting configurations such as : 124 | 1. you can hide or show title or positive/negative button(or both) 125 | 2. you can add a `customized view` into the `MDDialog`, and can add code to control the customized view in Builder' fuction `setContentViewOperator(...)` 126 | 3. you can set an `String[] messages` into `MDDialog`, and each item of messages will be one view in `MDDialog`, and can set `setOnItemClickListener(...)` for each item of messages. 127 | 4. you can customize the corner's radius of `MDDialog`. 128 | 5. `MDDialog` has the pressed effect of each messages item, and the shape of pressed effect is the same as item's shape 129 | 6. two ways to set the `MDDialog` width, the ratio of screen width, or the exact dimension
130 | 131 | ## Screenshot 132 |
133 | ![you can check the MDDialog_setView.png](https://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setview.png) 134 |

135 |
136 | ![SegmentControlView MDDialog_setMessages](https://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setmessages.png) 137 |
138 | 139 | ## Example 140 | first add dependences 141 | ``` 142 | dependencies { 143 | compile 'cn.carbs.android:MDDialog:1.0.0' 144 | } 145 | ``` 146 | how to build the `MDDialog` in java code 147 | ``` 148 | two mode to create MDDialog 149 | 1.set customize view : 150 | new MDDialog.Builder(ActivityMain.this) 151 | // .setContentView(customizedView) 152 | .setContentView(R.layout.content_dialog) 153 | .setContentViewOperator(new MDDialog.ContentViewOperator() { 154 | @Override 155 | public void operate(View contentView) { 156 | EditText et = (EditText) contentView.findViewById(R.id.edit0); 157 | et.setHint("hint set in operator"); 158 | } 159 | }) 160 | .setTitle("添加") 161 | .setNegativeButton(new View.OnClickListener() { 162 | @Override 163 | public void onClick(View v) { 164 | } 165 | }) 166 | .setPositiveButton(new View.OnClickListener() { 167 | @Override 168 | public void onClick(View v) { 169 | } 170 | }) 171 | .setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() { 172 | @Override 173 | public void onClick(View clickedView, View contentView) { 174 | EditText et = (EditText) contentView.findViewById(R.id.edit0); 175 | Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show(); 176 | } 177 | }) 178 | .setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() { 179 | @Override 180 | public void onClick(View clickedView, View contentView) { 181 | EditText et = (EditText) contentView.findViewById(R.id.edit1); 182 | Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show(); 183 | } 184 | }) 185 | .setWidthMaxDp(600) 186 | // .setShowTitle(false)//default is true 187 | // .setShowButtons(true)//default is true 188 | .create() 189 | .show(); 190 | 191 | 2.set String[] messages 192 | 193 | final String[] messages = new String[]{"两个黄鹂鸣翠柳,一行白鹭上青天。", 194 | "窗含西岭千秋雪,门泊东吴万里船。", 195 | "君不见,黄河之水天上来,奔流到海不复回;君不见,高堂明镜悲白发,朝如青丝暮如雪。"}; 196 | new MDDialog.Builder(ActivityMain.this) 197 | .setMessages(messages) 198 | .setTitle("一首古诗") 199 | .setNegativeButton(new View.OnClickListener() { 200 | @Override 201 | public void onClick(View v) { 202 | } 203 | }) 204 | .setPositiveButton(new View.OnClickListener() { 205 | @Override 206 | public void onClick(View v) { 207 | Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show(); 208 | } 209 | }) 210 | .setOnItemClickListener(new MDDialog.OnItemClickListener() { 211 | @Override 212 | public void onItemClicked(int index) { 213 | Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show(); 214 | } 215 | }) 216 | .setWidthMaxDp(600) 217 | .setShowTitle(false) 218 | .setShowButtons(true) 219 | .create() 220 | .show(); 221 | 222 | ``` 223 | 224 | ## License 225 | 226 | Copyright 2016 Carbs (MDDialog) 227 | 228 | Licensed under the Apache License, Version 2.0 (the "License"); 229 | you may not use this file except in compliance with the License. 230 | You may obtain a copy of the License at 231 | 232 | http://www.apache.org/licenses/LICENSE-2.0 233 | 234 | Unless required by applicable law or agreed to in writing, software 235 | distributed under the License is distributed on an "AS IS" BASIS, 236 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 237 | See the License for the specific language governing permissions and 238 | limitations under the License. 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.5.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "cn.carbs.android.mddialog" 9 | minSdkVersion 8 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile project(':library') 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | testCompile 'junit:junit:4.12' 26 | compile 'com.android.support:appcompat-v7:23.2.1' 27 | } 28 | -------------------------------------------------------------------------------- /example/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\rick.wang.E-BAO\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /example/src/androidTest/java/cn/carbs/android/mddialog/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package cn.carbs.android.mddialog; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/src/main/java/cn/carbs/android/mddialog/ActivityMain.java: -------------------------------------------------------------------------------- 1 | package cn.carbs.android.mddialog; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.EditText; 8 | import android.widget.Toast; 9 | 10 | import cn.carbs.android.library.MDDialog; 11 | 12 | public class ActivityMain extends AppCompatActivity { 13 | 14 | Button button1; 15 | Button button2; 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_main); 20 | init(); 21 | } 22 | 23 | private void init(){ 24 | final String[] messages = new String[]{"两个黄鹂鸣翠柳,一行白鹭上青天。", 25 | "窗含西岭千秋雪,门泊东吴万里船。", 26 | "君不见,黄河之水天上来,奔流到海不复回;君不见,高堂明镜悲白发,朝如青丝暮如雪。"}; 27 | button1 = (Button)this.findViewById(R.id.button1); 28 | button2 = (Button)this.findViewById(R.id.button2); 29 | 30 | /*final LinearLayout ll = new LinearLayout(this); 31 | LayoutInflater.from(this).inflate(R.layout.content, ll);*/ 32 | 33 | button1.setOnClickListener(new View.OnClickListener() { 34 | 35 | @Override 36 | public void onClick(View v) { 37 | new MDDialog.Builder(ActivityMain.this) 38 | // .setContentView(ll) 39 | .setContentView(R.layout.content_dialog) 40 | .setContentViewOperator(new MDDialog.ContentViewOperator() { 41 | @Override 42 | public void operate(View contentView) { 43 | EditText et = (EditText)contentView.findViewById(R.id.edit0); 44 | et.setHint("hint set in operator"); 45 | } 46 | }) 47 | // .setMessages(messages) 48 | .setTitle("添加") 49 | .setNegativeButton(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View v) { 52 | } 53 | }) 54 | .setPositiveButton(new View.OnClickListener() { 55 | @Override 56 | public void onClick(View v) { 57 | 58 | } 59 | }) 60 | .setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() { 61 | 62 | @Override 63 | public void onClick(View clickedView, View contentView) { 64 | EditText et = (EditText)contentView.findViewById(R.id.edit0); 65 | Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show(); 66 | } 67 | }) 68 | .setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() { 69 | 70 | @Override 71 | public void onClick(View clickedView, View contentView) { 72 | EditText et = (EditText)contentView.findViewById(R.id.edit1); 73 | Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show(); 74 | } 75 | }) 76 | .setOnItemClickListener(new MDDialog.OnItemClickListener() { 77 | @Override 78 | public void onItemClicked(int index) { 79 | if (index == 0) { 80 | Toast.makeText(getApplicationContext(), "index 0", Toast.LENGTH_SHORT).show(); 81 | } else if (index == 1) { 82 | Toast.makeText(getApplicationContext(), "index 1", Toast.LENGTH_SHORT).show(); 83 | } else if (index ==2 ){ 84 | Toast.makeText(getApplicationContext(), "index 2", Toast.LENGTH_SHORT).show(); 85 | } 86 | } 87 | }) 88 | .setWidthMaxDp(600) 89 | // .setShowTitle(false) 90 | .setShowButtons(true) 91 | .create() 92 | .show(); 93 | } 94 | }); 95 | 96 | button2.setOnClickListener(new View.OnClickListener() { 97 | 98 | @Override 99 | public void onClick(View v) { 100 | new MDDialog.Builder(ActivityMain.this) 101 | .setMessages(messages) 102 | .setTitle("一首古诗") 103 | .setNegativeButton(new View.OnClickListener() { 104 | @Override 105 | public void onClick(View v) { 106 | } 107 | }) 108 | .setPositiveButton(new View.OnClickListener() { 109 | @Override 110 | public void onClick(View v) { 111 | Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show(); 112 | } 113 | }) 114 | .setOnItemClickListener(new MDDialog.OnItemClickListener() { 115 | @Override 116 | public void onItemClicked(int index) { 117 | Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show(); 118 | } 119 | }) 120 | .setWidthMaxDp(600) 121 | .setShowTitle(false) 122 | .setShowButtons(true) 123 | .create() 124 | .show(); 125 | } 126 | }); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /example/src/main/res/drawable/color_cursor.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |