レイアウトをカスタマイズできるダイアログ---CommonDialog
3018 ワード
Android , , , , dialog , dialog, , , popupwindow , , 。 :
、 :
package com.ytd.finding.widget;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.ytd.finding.R;
public class CommonDialog extends Dialog {
public CommonDialog(Context context) {
super(context);
}
public CommonDialog(Context context, int theme) {
super(context, theme);
}
public static abstract class Builder {
private Context context;
final CommonDialog dialog;
public Builder(Context context) {
this.context = context;
dialog = new CommonDialog(context, R.style.Dialog);
}
public View getView(int layoutId) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(layoutId, null);
dialog.addContentView(layout, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
return layout;
}
public CommonDialog build(int layoutId){
onViewCreated(getView(layoutId),dialog);
return dialog;
}
abstract public void onViewCreated(View view,Dialog dialog);
}
}
、 style: // style
:
、
private void showDialog() {
CommonDialog dialog = new CommonDialog.Builder(this) {
@Override
public void onViewCreated(View view, Dialog dialog) {
// , , 。。。
// findViewById().....
}
}.build(R.layout.dialog_waiting); //
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
、
FragmeLayout
LinearLayout