Dialog全屏,一行代码搞定


第一步,自定义一个Dialog继承自Dialog;

第二步,在设置setContentView(R.layout.dialog_your_layout)后 调用以下代码


getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);//设置Dialog为全屏
 
 
/***************************************我是分隔线********************************************/
 
public class UploadImageDialog extends Dialog {


    private Context mContext;
    public TextView tvAlbum;
    public TextView tvCamera;
    public TextView tvCancell;

    private View view;

    public UploadImageDialog(Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_uploadimage);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);//设置Dialogquan  tvAlbum = (TextView) findViewById(R.id.m_tv_dialog_album);
        tvCamera = (TextView) findViewById(R.id.m_tv_dialog_camera);
        tvCancell = (TextView) findViewById(R.id.m_tv_dialog_cancel);
        view = findViewById(R.id.m_view_divider);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
 
  
 
  
/************************************************************************************/
 
  
 
  
"1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical">

    <View  android:id="@+id/m_view_divider"  android:layout_width="match_parent"  android:layout_height="0dp"  android:layout_weight="1" />

    <TextView  android:textColor="@color/color_base"  android:background="@color/color_blank"  android:text="@string/uploadimage_dialog_str1"  style="@style/UploadimageTextView"  android:id="@+id/m_tv_dialog_camera"  />

    <View  android:background="@color/uploadimage_divider"  android:layout_width="match_parent"  android:layout_height="1dp"/>

    <TextView  android:textColor="@color/color_base"  android:background="@color/color_blank"  android:text="@string/uploadimage_dialog_str2"  android:id="@+id/m_tv_dialog_album"  style="@style/UploadimageTextView" />

    <TextView  android:textColor="@color/color_blank"  android:background="@color/color_base"  android:text="@string/uploadimage_dialog_str3"  android:id="@+id/m_tv_dialog_cancel"  style="@style/UploadimageTextView" />


LinearLayout>




你可能感兴趣的:(Android开发)