浅析浅析Android中常见三种弹框在项目中的应用中常见三种弹框在项目中的应用
一丶概述一丶概述
弹框在Android项目中经常出现,常见的实现方法有三种:Dialog 弹框,Window弹框,Activity伪弹框。本文就说一说三种弹
框的实现及在项目中的运用。
二丶演示图二丶演示图
图一为常见的三种弹框(文末上链接),图二为项目中用到的Activity伪弹框
三丶正文三丶正文
1.Dialog弹框弹框
先看一篇一篇文章:
android 8种对话框(种对话框(Dialog)使用方法汇总)使用方法汇总
Dialog是系统自带的弹框,然而常常因为UI不好看而遭嫌弃,常需要自定义
public class MyDialog extends Dialog implements android.view.View.OnClickListener {
private Context mContext;
private String mTitle;
private String mDetail;
private TextView mTextTitle;
private TextView mTextDetail;
private TextView mButtonYes;
private TextView mButtonNo;
private onClickInterface mOnclClickInterface;
public MyDialog(Context context, String title, String detail) {
super(context, R.style.MyDialogStyle);
this.mContext = context;
this.mTitle = title;
this.mDetail = detail;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
initView();
}
private void initView() {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.layout_dialog, null);
setContentView(view);
mButtonYes = (TextView) view.findViewById(R.id.dialog_yes);
mButtonNo = (TextView) view.findViewById(R.id.dialog_no);
mTextTitle = (TextView) view.findViewById(R.id.dialog_title);
mTextDetail = (TextView) view.findViewById(R.id.dialog_detail);
mTextTitle.setText(mTitle);