使用Activity实现dialog效果

说明:公司的需求是要在底部弹框中增加一个输入框,并且最底部分是时间选择器,点击编辑框时,遮挡住时间选择框布局

使用fragmentDialog无法控制输入框

 1、在styles中设置Activity的弹框主题以及弹出的动画样式

 <!--ActivityDialog底部弹出样式 start-->
    <style name="ActivityDialogTheme">
        <item name="android:windowBackground">@android:color/transparent
        </item> <!--设置dialog的背景,此处为系统给定的透明值-->
        <item name="android:windowFrame">@null</item>                <!--Dialog的windowFrame框为无-->
        <item name="android:windowNoTitle">true</item>         <!--是否显示标题-->
        <item name="android:windowIsFloating">true</item>            <!--是否浮现在activity之上-->
        <item name="android:windowIsTranslucent">true</item>         <!--是否半透明-->
        <item name="android:windowContentOverlay">@null</item>       <!--是否有覆盖-->
        <item name="android:windowAnimationStyle">@style/AnimationActivity
        </item>   <!--设置Activity出现方式-->
        <item name="android:backgroundDimEnabled">true</item>        <!--背景是否模糊显示-->
        <item name="android:windowTranslucentStatus">true</item>    <!-- 设置背景透明色-->
        <item name="android:windowTranslucentNavigation">true</item>
    </style>

//弹出动画样式

 <!--从底部弹出的动画样式-->
    <style name="AnimationActivity" mce_bogus="1" parent="@android:style/Animation.Activity">
        <!--一个activity创建进入的效果。-->
        <item name="android:activityOpenEnterAnimation">@anim/slide_in_bottom</item>
        <!--一个activity还没有finish()下退出效果, 比如有俩个activity A与B 首先启动A 然后再启动B 那么A还没有finish()  这时A的退出效果。-->
        <item name="android:activityOpenExitAnimation">@anim/slide_out_bottom</item>
        <!--表示上一个activity返回进入效果 比如有俩个activity A与B  B在最上面,B退出(finish)后 A重新进入的效果。-->
        <item name="android:activityCloseEnterAnimation">@anim/slide_in_bottom</item>
        <!--表示的是activity finish()之后的效果 比如有俩个activity A与B B退出后会被finish() 那么B的退出效果在这定义。-->
        <item name="android:activityCloseExitAnimation">@anim/slide_out_bottom</item>
    </style>

2、退出和进入动画布局

(1)放在res文件下,创建anim文件并创建slide_out_bottom.xml 退出动画布局

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="0%"
        android:startOffset="0"
        android:toYDelta="100%" />
</set>

(2)创建slide_out_bottom 进入动画布局

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="300"
        android:fromYDelta="100%"
        android:startOffset="0"
        android:toYDelta="0%" />
</set>

3、代码部分

(1)创建MinePetTimeActivityDialog类

 布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context=".ui.dialog.MinePetTimeActivityDialog">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/rl"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

            <RelativeLayout
                android:id="@+id/rl_root"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <cn.ipets.chongmingandroid.ui.widget.roundlayout.RCRelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:focusable="false"
                        android:focusableInTouchMode="false"
                        app:round_corner_top_left="12dp"
                        app:round_corner_top_right="12dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@drawable/shape_dialog_white_top"
                            android:orientation="vertical">


                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="vertical">


                                <RelativeLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="@dimen/dp51"
                                    android:orientation="horizontal">

                                    <TextView
                                        android:id="@+id/tv_cancel"
                                        style="@style/TextViewFontNormal"
                                        android:layout_width="wrap_content"
                                        android:layout_height="@dimen/dp51"
                                        android:layout_alignParentStart="true"
                                        android:layout_centerVertical="true"
                                        android:layout_marginStart="@dimen/dp20"
                                        android:gravity="center_vertical"
                                        android:text="取消"
                                        android:textColor="@color/colorGrayText1"
                                        android:textSize="16sp" />

                                    <TextView
                                        android:id="@+id/tv_title"
                                        style="@style/TextViewFontMedium"
                                        android:layout_width="match_parent"
                                        android:layout_height="@dimen/dp50"
                                        android:layout_centerInParent="true"
                                        android:ellipsize="end"
                                        android:gravity="center"
                                        android:paddingLeft="10dp"
                                        android:paddingRight="10dp"
                                        android:singleLine="true"
                                        android:text="疫苗记录"
                                        android:textColor="@color/colorBtnText"
                                        android:textSize="16sp" />

                                    <TextView
                                        android:id="@+id/tv_confirm"
                                        style="@style/TextViewFontMedium"
                                        android:layout_width="wrap_content"
                                        android:layout_height="@dimen/dp51"
                                        android:layout_alignParentEnd="true"
                                        android:layout_centerVertical="true"
                                        android:layout_marginEnd="@dimen/dp20"
                                        android:gravity="center_vertical"
                                        android:text="确定"
                                        android:textColor="@color/colorBlueText"
                                        android:textSize="16sp" />

                                    <View
                                        android:layout_width="match_parent"
                                        android:layout_height="0.5dp"
                                        android:layout_alignParentBottom="true"
                                        android:background="@color/colorLine" />
                                </RelativeLayout>


                                <RelativeLayout
                                    android:id="@+id/rl_date"
                                    android:layout_width="match_parent"
                                    android:layout_height="@dimen/dp48"
                                    android:focusable="true"
                                    android:focusableInTouchMode="false">

                                    <TextView
                                        android:id="@+id/tv_date"
                                        style="@style/TextViewFontMedium"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_centerVertical="true"
                                        android:layout_marginStart="@dimen/dp20"
                                        android:focusable="false"
                                        android:focusableInTouchMode="false"
                                        android:gravity="center_vertical"
                                        android:text="注射日期"
                                        android:textColor="@color/colorBlackText"
                                        android:textSize="16sp"
                                        tools:ignore="Suspicious0dp" />

                                    <TextView
                                        android:id="@+id/tv_time"
                                        style="@style/TextViewFontMedium"
                                        android:layout_width="wrap_content"
                                        android:layout_height="match_parent"
                                        android:layout_alignParentEnd="true"
                                        android:layout_centerVertical="true"
                                        android:layout_marginEnd="@dimen/dp20"
                                        android:focusable="false"
                                        android:focusableInTouchMode="false"
                                        android:gravity="center_vertical|end"
                                        android:text="2020-01-01"
                                        android:textColor="@color/colorBlackText"
                                        android:textSize="16sp" />

                                    <View
                                        android:layout_width="match_parent"
                                        android:layout_height="0.5dp"
                                        android:layout_alignParentBottom="true"
                                        android:background="@color/colorLine"
                                        android:focusable="false"
                                        android:focusableInTouchMode="false" />
                                </RelativeLayout>


                                <RelativeLayout
                                    android:id="@+id/rl_bei_zhu"
                                    android:layout_width="match_parent"
                                    android:layout_height="@dimen/dp48"
                                    android:focusable="false"
                                    android:focusableInTouchMode="false"
                                    android:gravity="center_vertical"
                                    android:orientation="horizontal">

                                    <TextView
                                        android:id="@+id/tv_bei_zhu"
                                        style="@style/TextViewFontMedium"
                                        android:layout_width="wrap_content"
                                        android:layout_height="match_parent"
                                        android:layout_marginStart="@dimen/dp20"
                                        android:gravity="center_vertical"
                                        android:text="备注"
                                        android:textColor="@color/colorGrayText1"
                                        android:textSize="16sp"
                                        tools:ignore="Suspicious0dp" />

                                    <EditText
                                        android:id="@+id/et_bei_zhu"
                                        style="@style/TextViewFontMedium"
                                        android:layout_width="@dimen/dp285"
                                        android:layout_height="match_parent"
                                        android:layout_alignParentEnd="true"
                                        android:layout_marginEnd="@dimen/dp20"
                                        android:background="@null"
                                        android:ellipsize="end"
                                        android:gravity="right|center_vertical"
                                        android:hint="请填写疫苗名称"
                                        android:inputType="text"
                                        android:maxLength="20"
                                        android:maxLines="1"
                                        android:singleLine="true"
                                        android:textColor="@color/colorBlackText"
                                        android:textColorHint="@color/colorGrayText1"
                                        android:textSize="16sp" />

                                    <View
                                        android:layout_width="match_parent"
                                        android:layout_height="0.5dp"
                                        android:layout_alignParentBottom="true"
                                        android:background="@color/colorLine" />
                                </RelativeLayout>

                                <View
                                    android:id="@+id/v"
                                    android:layout_width="0dp"
                                    android:layout_height="0dp" />
                            </LinearLayout>


                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_gravity="bottom"
                                android:orientation="horizontal">

                                <FrameLayout
                                    android:id="@+id/fragment"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:focusable="false"
                                    android:focusableInTouchMode="false" />
                            </LinearLayout>
                        </LinearLayout>

                    </cn.ipets.chongmingandroid.ui.widget.roundlayout.RCRelativeLayout>

                </LinearLayout>

            </RelativeLayout>
        </ScrollView>
    </LinearLayout>
</RelativeLayout>

java代码,主要是启动动画

//定义Activity退出动画的成员变量
    protected int activityCloseEnterAnimation;
    protected int activityCloseExitAnimation;





//在onCreate方法中初始化
 TypedArray activityStyle = getTheme().obtainStyledAttributes(new int[]{android.R.attr.windowAnimationStyle});
        int windowAnimationStyleResId = activityStyle.getResourceId(0, 0);
        activityStyle.recycle();
        activityStyle = getTheme().obtainStyledAttributes(windowAnimationStyleResId, new int[]{android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation});
        activityCloseEnterAnimation = activityStyle.getResourceId(0, 0);
        activityCloseExitAnimation = activityStyle.getResourceId(1, 0);
        activityStyle.recycle();



 //重写finish方法
    @Override
    public void finish() {
        super.finish();
        //finish时调用退出动画
        overridePendingTransition(activityCloseEnterAnimation, activityCloseExitAnimation);
    }

(2)在androidmanifest.xml设置主题

<activity
            android:name=".ui.dialog.MinePetTimeActivityDialog"
            android:theme="@style/ActivityDialogTheme"
            android:windowSoftInputMode="adjustResize|stateHidden" />
        <activity

4、完整java代码

package cn.ipets.chongmingandroid.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnTimeSelectChangeListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.blankj.utilcode.util.SizeUtils;
import com.chongminglib.util.ScreenUtil;
import com.chongminglib.util.ScreenUtils;
import com.contrarywind.view.WheelView;

import org.greenrobot.eventbus.EventBus;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.ipets.chongmingandroid.R;
import cn.ipets.chongmingandroid.event.SendMinePetDialogDataEvent;
import cn.ipets.chongmingandroid.model.entity.PetHealthNoteBean;
import cn.ipets.chongmingandroid.model.entity.PetHealthRemindBean;
import cn.ipets.chongmingandroid.util.DateUtils;
import cn.ipets.chongmingandroid.util.KeyBoardUtil;
import cn.ipets.chongmingandroid.util.ToastUtils;

public class MinePetTimeActivityDialog extends Activity implements View.OnClickListener {
    @BindView(R.id.rl)
    LinearLayout relativeLayout;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    @BindView(R.id.tv_date)
    TextView tvDate;
    @BindView(R.id.tv_bei_zhu)
    TextView tvBeiZhu;
    @BindView(R.id.et_bei_zhu)
    EditText etBeiZhu;
    @BindView(R.id.fragment)
    FrameLayout fragment;

    @BindView(R.id.rl_date)
    RelativeLayout rlDate;
    @BindView(R.id.rl_bei_zhu)
    RelativeLayout rlBeiZhu;
    @BindView(R.id.v)
    View v;


    //定义Activity退出动画的成员变量
    protected int activityCloseEnterAnimation;
    protected int activityCloseExitAnimation;
    private Context mContext;
    private TimePickerView pvTime;
    private long time = System.currentTimeMillis();
    private String mType = "";
    private int mPetId;
    private boolean isNotes;
    private PetHealthNoteBean.DataBean.ContentBean bean;
    private boolean isRemindToNotes;
    private PetHealthRemindBean.DataBean beanHealth;
    private boolean isSelect;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_mine_pet_time_dialog);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        mType = getIntent().getStringExtra("type");
        mPetId = getIntent().getIntExtra("petId", 0);
        isNotes = getIntent().getBooleanExtra("isNotes", false);
        bean = (PetHealthNoteBean.DataBean.ContentBean) getIntent().getSerializableExtra("bean");
        beanHealth = (PetHealthRemindBean.DataBean) getIntent().getSerializableExtra("beanHealth");
        isRemindToNotes = getIntent().getBooleanExtra("isRemindToNotes", false);
        ButterKnife.bind(this);
        initView();
        initTransferData();
        initListener();
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (isSelect) {
            etBeiZhu.setFocusable(true);
            etBeiZhu.requestFocus();
            etBeiZhu.setFocusableInTouchMode(true);
            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.showSoftInput(etBeiZhu, InputMethodManager.SHOW_IMPLICIT);
        }
        Window window = getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.5f;//设置灰度.
        window.setAttributes(windowParams);
    }

    private void initView() {
        TypedArray activityStyle = getTheme().obtainStyledAttributes(new int[]{android.R.attr.windowAnimationStyle});
        int windowAnimationStyleResId = activityStyle.getResourceId(0, 0);
        activityStyle.recycle();
        activityStyle = getTheme().obtainStyledAttributes(windowAnimationStyleResId, new int[]{android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation});
        activityCloseEnterAnimation = activityStyle.getResourceId(0, 0);
        activityCloseExitAnimation = activityStyle.getResourceId(1, 0);
        activityStyle.recycle();

        //设置布局在底部
        getWindow().setGravity(Gravity.BOTTOM);
        //设置布局填充满宽度
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(layoutParams);
        initTimePicker();
        setYiMiaoTextColor(1);

        tvTime.setText(DateUtils.getStringDateYMD());

    }

    @SuppressLint("ClickableViewAccessibility")
    private void initListener() {
        relativeLayout.setOnClickListener(this);
        rlDate.setOnClickListener(this);
        tvCancel.setOnClickListener(this);
        tvConfirm.setOnClickListener(this);
        etBeiZhu.setOnTouchListener((v, event) -> {
            etBeiZhu.setFocusable(true);
            etBeiZhu.setFocusableInTouchMode(true);
            if (event.getAction() == MotionEvent.ACTION_UP) {
                isSelect = true;
                setYiMiaoTextColor(2);
            }
            return false;
        });

        rlBeiZhu.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
            Rect r = new Rect();
            //获取当前界面可视部分
            getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
            //获取屏幕的高度
            int screenHeight = getWindow().getDecorView().getRootView().getHeight();
            //此处就是用来获取键盘的高度的, 在键盘没有弹出的时候 此高度为0 键盘弹出的时候为一个正数
            int heightDifference = screenHeight - r.bottom;
            lockContentHeight();
            unlockContentHeightDelayed(heightDifference);

        });
    }


    /**
     * 锁定内容高度,防止跳闪
     */
    private void lockContentHeight() {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rlBeiZhu.getLayoutParams();
        params.height = rlBeiZhu.getHeight();
        params.weight = 0.0F;
    }


    /**
     * 释放被锁定的内容高度
     */
    public void unlockContentHeightDelayed(final int heightDifference) {
        etBeiZhu.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (rlBeiZhu == null) {
                    return;
                }
                ((LinearLayout.LayoutParams) rlBeiZhu.getLayoutParams()).weight = 1.0F;
                ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
                //576
//                layoutParams.height = heightDifference - ScreenUtils.dp2px(mContext, 105);
                layoutParams.height = heightDifference - 120;
                v.setLayoutParams(layoutParams);
            }
        }, 10L);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_date:
                KeyBoardUtil.closeKeybord(etBeiZhu, mContext);
                etBeiZhu.setFocusable(false);
                etBeiZhu.setFocusableInTouchMode(false);
                setYiMiaoTextColor(1);
                break;
            case R.id.rl:
            case R.id.tv_cancel:
                EventBus.getDefault().post(new SendMinePetDialogDataEvent(new HashMap<>(), 4));//取消
                finish();
                break;
            case R.id.tv_confirm:
                Map map = new HashMap();
                if (map.size() > 0) {
                    map.clear();
                }
                map.put("type", "VACCINE");
                map.put("content", etBeiZhu.getText().toString().trim());
                if (time >= System.currentTimeMillis()) {
                    ToastUtils.showCustomToast(mContext, "记录日期不能大于当前日期");
                    return;
                }
                map.put("noteTime", "" + time);
                map.put("petId", mPetId);
                if (isRemindToNotes) {
                    map.put("petHealthNoteRemindId", beanHealth.getId());
                }
                if (!isNotes && !isRemindToNotes) {
                    EventBus.getDefault().post(new SendMinePetDialogDataEvent(map, 1));//1新添加
                } else if (isNotes) {
                    EventBus.getDefault().post(new SendMinePetDialogDataEvent(map, 2));// 2记录跳转
                } else {
                    EventBus.getDefault().post(new SendMinePetDialogDataEvent(map, 3));//3提醒转记录
                }
                finish();
                break;
        }

    }


    private void initTransferData() {
        if (isNotes) {
            tvTime.setText(DateUtils.longToDate1(Long.parseLong(bean.getNoteTime())));
            time = Long.parseLong(bean.getNoteTime());
            if (!TextUtils.isEmpty(bean.getContent())) {
                etBeiZhu.setText(bean.getContent());
            }
        }

    }

    private void setYiMiaoTextColor(int i) {//1 日期 2 编辑框
        switch (i) {
            case 1:
                tvDate.setTextColor(mContext.getResources().getColor(R.color.colorBlackText));
                tvTime.setTextColor(mContext.getResources().getColor(R.color.colorBlackText));
                tvBeiZhu.setTextColor(mContext.getResources().getColor(R.color.colorGrayText1));
                etBeiZhu.setTextColor(mContext.getResources().getColor(R.color.colorGrayText1));

                break;
            case 2:
                tvDate.setTextColor(mContext.getResources().getColor(R.color.colorGrayText1));
                tvTime.setTextColor(mContext.getResources().getColor(R.color.colorGrayText1));
                tvBeiZhu.setTextColor(mContext.getResources().getColor(R.color.colorBlackText));
                etBeiZhu.setTextColor(mContext.getResources().getColor(R.color.colorBlackText));
                break;
        }

    }

    private void initTimePicker() {
        //控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释)
        //因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
        Calendar selectedDate = Calendar.getInstance();

        if (isNotes) {
            selectedDate.set(Integer.parseInt(DateUtils.getDateToString(Long.parseLong(bean.getNoteTime()), "yyyy")),
                    Integer.parseInt(DateUtils.getDateToString(Long.parseLong(bean.getNoteTime()), "MM")) - 1,
                    Integer.parseInt(DateUtils.getDateToString(Long.parseLong(bean.getNoteTime()), "dd")));

        }
        Calendar startDate = Calendar.getInstance();

        startDate.set(1975, 0, 1);


        Calendar endDate = Calendar.getInstance();
        endDate.set(2095, 11, 31);
        //时间选择器
        pvTime = new TimePickerBuilder(mContext, (date, v) -> {//选中事件回调
        })
                .setTimeSelectChangeListener(new OnTimeSelectChangeListener() {//选中事件回调时时监听
                    @Override
                    public void onTimeSelectChanged(Date date) {
                        if (tvTime != null) {
                            tvTime.setText(DateUtils.dateToString(date, "yyyy-MM-dd"));
                        }
                        time = date.getTime();
                    }
                })
                .setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {

                    @Override
                    public void customLayout(View v) {
                        final TextView tvSubmit = v.findViewById(R.id.tv_finish);
                        ImageView ivCancel = v.findViewById(R.id.iv_cancel);
                        WheelView year = v.findViewById(R.id.year);
                        year.setTextSize(45);
                        year.setCyclic(true);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvTime.returnData();
                                /*pvTime.dismiss();*/
                            }
                        });
                        ivCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                /*pvTime.dismiss();*/
                            }
                        });
                    }
                })
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "", "", "") //设置空字符串以隐藏单位提示   hide label
//                .setDividerColor(Color.DKGRAY)
//                .setContentTextSize(20)//设置文字大小
                .setItemVisibleCount(7)
                .setDate(selectedDate)//选中的时间
                .setRangDate(startDate, endDate)
//                .setRangDate(startDate, endDate)
                .setDecorView(fragment)//非dialog模式下,设置ViewGroup, pickerView将会添加到这个ViewGroup中
                .setOutSideColor(0x00000000)
                .setOutSideCancelable(false)
                .isAlphaGradient(true)//透明度渐变
                .setDividerColor(mContext.getResources().getColor(R.color.colorC8C7CC))
                .setTextColorCenter(mContext.getResources().getColor(R.color.colorBtnText))
                .setTextColorOut(mContext.getResources().getColor(R.color.color999999))
//                .setLineSpacingMultiplier(1.8f)//设置行高
                .build();
        pvTime.show();
        pvTime.setKeyBackCancelable(false);//系统返回键监听屏蔽掉

    }

    //新创建
    public static void startDialogActivity(Context context, String type, int petId) {
        Intent intent = new Intent(context, MinePetTimeActivityDialog.class);
        intent.putExtra("type", type);
        intent.putExtra("petId", petId);
        context.startActivity(intent);
    }

    //记录专用

    public static void startDialogActivity(Context context, String type, int petId, boolean isNotes, PetHealthNoteBean.DataBean.ContentBean bean) {
        Intent intent = new Intent(context, MinePetTimeActivityDialog.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("bean", bean);
        intent.putExtras(bundle);
        intent.putExtra("type", type);
        intent.putExtra("petId", petId);
        intent.putExtra("isNotes", isNotes);
        context.startActivity(intent);
    }

    //提醒转记录
    public static void startDialogActivity(Context context, String type, int petId, boolean isRemindToNotes, PetHealthRemindBean.DataBean bean) {
        Intent intent = new Intent(context, MinePetTimeActivityDialog.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable("beanHealth", bean);
        intent.putExtras(bundle);
        intent.putExtra("type", type);
        intent.putExtra("petId", petId);
        intent.putExtra("isRemindToNotes", isRemindToNotes);
        context.startActivity(intent);
    }

    //重写finish方法
    @Override
    public void finish() {
        super.finish();
        //finish时调用退出动画
        overridePendingTransition(activityCloseEnterAnimation, activityCloseExitAnimation);
    }


    @Override
    protected void onDestroy() {
        mType = "";
        mPetId = 0;
        isNotes = false;
        bean = null;
        super.onDestroy();
    }
}

效果图

发布了59 篇原创文章 · 获赞 13 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/Hunter2916/article/details/104259992