MDDialog
??
MDDialog
??? Material Designed
??? Dialog
?????????????????????????? ContentView
???? ContentView
?????????????????????????????dialog???????????????????????UI??????????????
??
?? Material Designed
??? Dialog
????????MD????????????? AlertDialog
???????? MDDialog
?
MDDialog
??????????
- ??????/??title???/?? ??/?????????????button???UI??????????????
- ???
MDDialog
????????View
????????MDDialog
????setContentViewOperator(...)
??????????view???? - ???
MDDialog
??String[] messages
???MDDialog
?builder
???????????String
??????????setOnItemClickListener(...)
???????????? - ??????
MDialog
?????????? MDDialog
?????message
?????????????????item
??????????- ??????????
MDDialog
?????????????????????????????
Author:Carbs.Wang
Email:yeah0126#yeah.net
![you can check the MDDialog_setView.png]( ??https://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setview.png)
![??message MDDialog_setMessages]( https://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setmessages.png)
??
??????
dependencies {
compile 'cn.carbs.android:MDDialog:1.0.0'
}
? java
????? MDDialog
???????????MDDialog?????????????
1.?MDDialog?????View:
new MDDialog.Builder(ActivityMain.this) //
.setContentView(customizedView)
.setContentView(R.layout.content_dialog)
.setContentViewOperator(new MDDialog.ContentViewOperator() {
@Override
public void operate(View contentView) {
//???contentView??????????????View??layout??inflate???view
EditText et = (EditText) contentView.findViewById(R.id.edit0);
et.setHint("hint set in operator");
}
}
)
.setTitle("??")
.setNegativeButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
)
.setPositiveButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
)
.setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() {
@Override
public void onClick(View clickedView, View contentView) {
//???contentView??????????????View??layout??inflate???view?????????/??????contentView????????????
EditText et = (EditText) contentView.findViewById(R.id.edit0);
Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show();
}
}
)
.setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() {
@Override
public void onClick(View clickedView, View contentView) {
EditText et = (EditText) contentView.findViewById(R.id.edit1);
Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show();
}
}
)
.setWidthMaxDp(600) //
.setShowTitle(false)//default is true //
.setShowButtons(true)//default is true
.create()
.show();
2.?? String[] messages????String??????item?????????
final String[] messages = new String[]{
"????????????????",
"????????????????",
"????????????????????????????????????????"
}
;
new MDDialog.Builder(ActivityMain.this)
.setMessages(messages)
.setTitle("????")
.setNegativeButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
)
.setPositiveButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show();
}
}
)
.setOnItemClickListener(new MDDialog.OnItemClickListener() {
@Override
public void onItemClicked(int index) {
Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show();
}
}
)
.setWidthMaxDp(600)
.setShowTitle(false)
.setShowButtons(true)
.create()
.show();
#English
Abstract
a material designed style dialog, can add operation of content view, set messages, respond to onclick of messages items and so on
Introduction
the MDDialog
inspired by the Material Design
Pattern. You can get a MD style dialog quickly by using MDDialog Builder
. this MDDialog
has many interesting configurations such as :
- you can hide or show title or positive/negative button(or both)
- you can add a
customized view
into theMDDialog
, and can add code to control the customized view in Builder' fuctionsetContentViewOperator(...)
- you can set an
String[] messages
intoMDDialog
, and each item of messages will be one view inMDDialog
, and can setsetOnItemClickListener(...)
for each item of messages. - you can customize the corner's radius of
MDDialog
. MDDialog
has the pressed effect of each messages item, and the shape of pressed effect is the same as item's shape- two ways to set the
MDDialog
width, the ratio of screen width, or the exact dimension
Author:Carbs.Wang
Email:yeah0126#yeah.net
![you can check the MDDialog_setView.png]( Screenshothttps://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setview.png)
![SegmentControlView MDDialog_setMessages]( https://github.com/Carbs0126/Screenshot/blob/master/md_dialog_setmessages.png)
Example
first add dependences
dependencies {
compile 'cn.carbs.android:MDDialog:1.0.0'
}
how to build the MDDialog
in java code
two mode to create MDDialog
1.set customize view :
new MDDialog.Builder(ActivityMain.this) //
.setContentView(customizedView)
.setContentView(R.layout.content_dialog)
.setContentViewOperator(new MDDialog.ContentViewOperator() {
@Override
public void operate(View contentView) {
EditText et = (EditText) contentView.findViewById(R.id.edit0);
et.setHint("hint set in operator");
}
}
)
.setTitle("??")
.setNegativeButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
)
.setPositiveButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
)
.setPositiveButtonMultiListener(new MDDialog.OnMultiClickListener() {
@Override
public void onClick(View clickedView, View contentView) {
EditText et = (EditText) contentView.findViewById(R.id.edit0);
Toast.makeText(getApplicationContext(), "edittext 0 : " + et.getText(), Toast.LENGTH_SHORT).show();
}
}
)
.setNegativeButtonMultiListener(new MDDialog.OnMultiClickListener() {
@Override
public void onClick(View clickedView, View contentView) {
EditText et = (EditText) contentView.findViewById(R.id.edit1);
Toast.makeText(getApplicationContext(), "edittext 1 : " + et.getText(), Toast.LENGTH_SHORT).show();
}
}
)
.setWidthMaxDp(600) //
.setShowTitle(false)//default is true //
.setShowButtons(true)//default is true
.create()
.show();
2.set String[] messages
final String[] messages = new String[]{
"????????????????",
"????????????????",
"????????????????????????????????????????"
}
;
new MDDialog.Builder(ActivityMain.this)
.setMessages(messages)
.setTitle("????")
.setNegativeButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
)
.setPositiveButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "positive", Toast.LENGTH_SHORT).show();
}
}
)
.setOnItemClickListener(new MDDialog.OnItemClickListener() {
@Override
public void onItemClicked(int index) {
Toast.makeText(getApplicationContext(), messages[index], Toast.LENGTH_SHORT).show();
}
}
)
.setWidthMaxDp(600)
.setShowTitle(false)
.setShowButtons(true)
.create()
.show();
License
Copyright 2016 Carbs.Wang (MDDialog) Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.