基于github開源框架基礎(chǔ)上運用在自己的項目中,
效果如下:
本演示項目 基于Android Studio開發(fā),
在對應(yīng)moudle下的gradle.build中添加以下依賴
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.github.sd6352051.niftydialogeffects:niftydialogeffects:1.0.0@aar'
核心代碼列出:
String []type = {"Fadein", "Slideleft", "Slidetop", "SlideBottom", "Slideright", "Fall", "Newspager", "Fliph", "Flipv", "RotateBottom", "RotateLeft", "Slit", "Shake", "Sidefill"};
int i= (int) (type.length*Math.random());
Effectstype effect = null;
switch (i){
case 0:effect=Effectstype.Fadein;break;
case 1:effect=Effectstype.Slideright;break;
case 2:effect=Effectstype.Slideleft;break;
case 3:effect=Effectstype.Slidetop;break;
case 4:effect=Effectstype.SlideBottom;break;
case 5:effect=Effectstype.Newspager;break;
case 6:effect=Effectstype.Fall;break;
case 7:effect=Effectstype.Sidefill;break;
case 8:effect=Effectstype.Fliph;break;
case 9:effect=Effectstype.Flipv;break;
case 10:effect=Effectstype.RotateBottom;break;
case 11:effect=Effectstype.RotateLeft;break;
case 12:effect=Effectstype.Slit;break;
case 13:effect=Effectstype.Shake;break;
}
final NiftyDialogBuilder dialogBuilder = NiftyDialogBuilder.getInstance(this);
dialogBuilder
// 重點設(shè)置
.withEffect(effect) //設(shè)置對話框彈出樣式
//.setCustomView(R.layout.custom, MainActivity.this) // 設(shè)置自定義對話框的布局
.withDuration(700) //動畫顯現(xiàn)的時間(時間長就類似放慢動作)
// 基本設(shè)置
.withTitle("Info") //設(shè)置對話框標題
.withTitleColor("#FFFFFF") //設(shè)置標題字體顏色
.withDividerColor("#11000000") //設(shè)置分隔線的顏色
.withMessage("Are you sure logout?")//設(shè)置對話框顯示內(nèi)容
.withMessageColor("#FFFFFFFF") //設(shè)置消息字體的顏色
.withDialogColor("#FFE74C3C") //設(shè)置對話框背景的顏色
//.withIcon(getResources().getDrawable(R.drawable.logo)) //設(shè)置標題的圖標
// 設(shè)置是否模態(tài)蒸播,默認false,表示模態(tài)掘譬,
//要求必須采取行動才能繼續(xù)進行剩下的操作 | isCancelable(true)
.isCancelableOnTouchOutside(true)
.withButton1Text("Yes") //設(shè)置按鈕1的文本
.withButton2Text("No") //設(shè)置按鈕2的文本
.setButton1Click(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "I am btnYes", Toast.LENGTH_SHORT).show();
dialogBuilder.dismiss();
}
})
.setButton2Click(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "I am btnNo", Toast.LENGTH_SHORT).show();
dialogBuilder.dismiss();
}
})
.show();
app demo下載地址: http://fir.im/NiftyDialog