MaterialDialog
这个仿MD风格的对话框应该是史上最轻巧的!
一个极简且仿Material Design AlertDialog
代码:
这个库有以下特点:
- 极简而且体积小
- 仿Material Design AlertDialog
- 可更改按钮颜色
Gradle
compile ‘peter1303.material.MaterialDesignDialog‘
- 使用方法:
final MaterialDialog alert=new MaterialDialog(MainActivity.this);
alert.setTitle(“标题”)
.setMessage(“消息”)
.setPositiveButton(“确定”, new OnClickListener(){
@Override
public void onClick(View p1)
{
alert.dismiss();
}
})
.setNegativeButton("取消", new OnClickListener(){
@Override
public void onClick(View p1)
{
alert.dismiss();
}
})
.setNeutralButton("第三个", new OnClickListener(){
@Override
public void onClick(View p1)
{
}
})
.show();</pre>
- Neutral按钮事件方法:
alert.setNeutralButton(“第三个”, new OnClickListener(){
@Override
public void onClick(View p1)
{
}
});</pre>
- 自定义List方法:
List<String>list = new ArrayList<String>();
for(int i=0;i<10;i++){
list.add(“item”+i);
}
MaterialDialog alert=new MaterialDialog(MainActivity.this);
alert.setTitle("标题")
.setItems(list, new ListView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
{
Toast.makeText(MainActivity.this,""+p3,Toast.LENGTH_LONG).show();
}
})
.setItemsLongClick(new ListView.OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> p1, View p2, int p3, long p4)
{
Toast.makeText(MainActivity.this,"long "+p3,Toast.LENGTH_LONG).show();
return false;
}
})
.setPositiveButton("确定", new OnClickListener(){
@Override
public void onClick(View p1)
{
// TODO: Implement this method
}
})
.setNegativeButton("取消", new OnClickListener(){
@Override
public void onClick(View p1)
{
// TODO: Implement this method
}
})
.setNeutralButton("第三", new OnClickListener(){
@Override
public void onClick(View p1)
{
// TODO: Implement this method
}
})
.show();</pre>
- 可设置Title下面的view:
.setContentView();
- 可设置按钮颜色:
.setBackground;
- 设置是否可在外面取消:
.setCanceledOnTouchOutside(true/faise);
- 可设置View(会无法显示Title):
.setView:
- License
Copyright 2016 Peter&DevelopTeam
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.
博客使用:CC BY-NC-SA 3.0 Unported 协议进行许可
本文链接:https://peter1303.github.io/2018/01/28/MaterialDialog/