public class ActionSheet {
public interface OnActionSheetSelected {
void onClick(int whichButton);
}
private ActionSheet() {
}
public static Dialog showSheet(Context context, final OnActionSheetSelected actionSheetSelected,
OnCancelListener cancelListener) {
final Dialog dlg = new Dialog(context, R.style.ActionSheet);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.actionsheet, null);
final int cFullFillWidth = 10000;
layout.setMinimumWidth(cFullFillWidth);
TextView mContent = (TextView) layout.findViewById(R.id.content);
TextView mCancel = (TextView) layout.findViewById(R.id.cancel);
mContent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
actionSheetSelected.onClick(0);
dlg.dismiss();
}
});
mCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
actionSheetSelected.onClick(1);
dlg.dismiss();
}
});
Window w = dlg.getWindow();
WindowManager.LayoutParams lp = w.getAttributes();
lp.x = 0;
final int cMakeBottom = -1000;
lp.y = cMakeBottom;
lp.gravity = Gravity.BOTTOM;
dlg.onWindowAttributesChanged(lp);
dlg.setCanceledOnTouchOutside(false);
if (cancelListener != null)
dlg.setOnCancelListener(cancelListener);
dlg.setContentView(layout);
dlg.show();
return dlg;
}
}
转载于:https://my.oschina.net/oppo4545/blog/203851