自定义底部弹出Dialog(老掉牙的需求还是记录一下吧)

自定义底部弹出Dialog(老掉牙的需求还是记录一下吧)_第1张图片
(1)布局:
phonto_dialog.xml

"http://schemas.android.com/apk/res/android"
    style="@style/choice_dialog1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/shape_win_photo_bg"
    android:orientation="vertical"
    android:padding="20dp" >


    

其中:
shape_win_photo_bg


<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp" />

    <solid android:color="#404848" />

shape>

selector_photo_bg


<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <corners android:radius="5dp" />
            <solid android:color="#d81e06" />
        shape>
    item>

       <item android:state_focused="true">
        <shape android:shape="rectangle">
            <corners android:radius="5dp" />
            <solid android:color="#d81e06" />
        shape>
    item>

    <item >
        <shape android:shape="rectangle">
            <corners android:radius="5dp" />
            <solid android:color="#D0D0D0" />
        shape>
    item>
selector>

java中调用

    Dialog dialog = null;
    public void selectImg(){

        if(dialog != null && dialog.isShowing()){
            dialog.dismiss();
            return;
        }
        dialog = new Dialog(this);
        Button select_poto_btn, camera_poto_btn,btn_cancle_photo;
        View view = LayoutInflater.from(this).inflate(R.layout.phonto_dialog, null);
        select_poto_btn = (Button) view.findViewById(R.id.btn1);
        camera_poto_btn = (Button) view.findViewById(R.id.btn2);
        btn_cancle_photo = (Button) view.findViewById(R.id.btn_cancle_photo);
        select_poto_btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startImgIntent(SELECT_FROM_IMGS_REQUESTCODE);
                dialog.dismiss();

            }
        });
        camera_poto_btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                startTakePhoto();
                dialog.dismiss();
            }
        });

        btn_cancle_photo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });


        dialog.setContentView(view);
        WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
        attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
        attributes.gravity = Gravity.BOTTOM;
        attributes.windowAnimations = R.style.mydialogstyle;
        dialog.getWindow().setAttributes(attributes);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.show();
    }

其中:
mydialogstyle

  

其中push_bottom_in



<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="500"
        android:fromYDelta="100%p"
        android:toYDelta="0"        
     />      
set>

push_bottom_out



<set xmlns:android="http://schemas.android.com/apk/res/android" >


    <translate
        android:duration="500"
        android:fromYDelta="0"
        android:toYDelta="100%p" />
set>

你可能感兴趣的:(自定义底部弹出Dialog(老掉牙的需求还是记录一下吧))