android開發(fā)的朋友們,大家一家會(huì)遇到這樣的需求,需要在XX頁面,彈出層,然后在彈出層中進(jìn)行各種操作。
曾經(jīng)的方法,一個(gè)彈出層,對應(yīng)一個(gè)功能。
現(xiàn)在想想,寫的想死。
于是乎,ConciseDialog便被設(shè)計(jì)出來了。
使用方法如下:
first
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.deilsky:ConciseDialog:v1.1'
}
second
ConciseDialog.newInstance(R.layout.nav_dialog, new ConciseDialog.ReadyListener() {
@Override
public void onComplete(View view) {
initDialogView(view);
}
@Override
public void onError(String e) {
}
}).matchWidth(true)
.gravity(ConciseDialog.DialogGravity.MIDDLE)
.absolute(true)
.height(80)//高度 百分比
.show(MainActivity.this.getFragmentManager(), "test1");
private void initDialogView(final View v) {
title = v.findViewById(R.id.tv_d_title);
title.setText("測試標(biāo)題");
yes = v.findViewById(R.id.nav_yes);
yes.setText("是");
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "是", Toast.LENGTH_SHORT).show();
}
});
no = v.findViewById(R.id.nav_no);
no.setText("否");
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "否", Toast.LENGTH_SHORT).show();
}
});
}
third 講解
1.ConciseDialog 繼承于android.app.DialogFragment; 所以可以像正常的Dialog一樣使用
2.ConciseDialog.newInstance(R.layout.nav_dialog, new ConciseDialog.ReadyListener() {
@Override
public void onComplete(View view) {
initDialogView(view);//dialog成功彈出,加載layout成功時(shí),回調(diào)
}
@Override
public void onError(String e) {}
}) //根據(jù)使用需要,可以引入各種layout文件
3.gravity //顯示的位置:上,中,下
4.absolute //是否使用絕對寬高
5.matchWidth// 寬度是否滿屏
6.height //絕對模式下,高度為xxxdp;非絕對模式下,高度為屏幕的xx%
7.width //僅在matchWidth為false時(shí),生效;絕對模式下,寬度為xxxdp;非絕對模式下,寬度為屏幕的xx%
8.動(dòng)態(tài)切換layout/數(shù)據(jù)時(shí),需要為講解2中的代碼,進(jìn)行實(shí)例。通過onComplete(View view)進(jìn)行重置數(shù)據(jù)