弹框显示,跳转页面

时间:2021-11-18 20:38:26

1、弹窗显示界面要求如下:

弹框显示,跳转页面

2. 自定义弹窗界面布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/ll_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/x94"
android:layout_above="@+id/btn_pull_down"
android:layout_marginBottom="@dimen/y77"
android:orientation="vertical">

<ImageView
android:id="@+id/iv_left"
android:layout_width="@dimen/x98"
android:layout_height="@dimen/x98"
android:src="@drawable/dot_wanted" />

<TextView
android:id="@+id/tv_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/y16"
android:text="@string/points_within_the_wanted"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/y22" />
</LinearLayout>


<LinearLayout
android:id="@+id/ll
_right"
android:layout_width="
wrap_content"
android:layout_height="
wrap_content"
android:layout_alignTop="
@+id/ll_left"
android:layout_marginLeft="
@dimen/x94"
android:layout_toEndOf="
@+id/ll_left"
android:layout_toRightOf="
@+id/ll_left"
android:orientation="
vertical">

<ImageView
android:id="
@+id/iv_right"
android:layout_width="
@dimen/x98"
android:layout_height="
@dimen/x98"
android:src="
@drawable/delete_form_vehicle" />

<TextView
android:id="
@+id/tv_right"
android:layout_width="
wrap_content"
android:layout_height="
wrap_content"
android:layout_gravity="
center"
android:layout_marginTop="
@dimen/y16"
android:text="
@string/from_car_clear"
android:textColor="
@color/primary_text_default_material_dark"
android:textSize="
@dimen/y22" />
</LinearLayout>


<ImageView
android:id="
@+id/btn_pull_down"
android:layout_width="
@dimen/x40"
android:layout_height="
@dimen/x40"
android:layout_alignParentBottom="
true"
android:layout_marginBottom="
@dimen/y15"
android:layout_marginLeft="
@dimen/x26"
android:src="
@drawable/btn_pull_down"
android:visibility="
visible" />

</RelativeLayout>

3. 自定义弹窗控件

package com.sfnp.warehouse.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sfnp.warehouse.R;
import com.sfnp.warehouse.base.BaseDialog;
import com.sfnp.warehouse.util.StringUtils;

/**
* Created by 01139949 on 2017/6/14.
*/


public class WaybillActionDialog extends BaseDialog {
private LinearLayout llLeft;
private LinearLayout llRight;
private OnWaybillActionListener waybillActionListener;
private ImageView ivPullDown;
private ImageView ivLeft;
private ImageView ivRight;
private TextView tvLeft;
private TextView tvRight;
private String leftText;
private String rightText;
private int leftRes;
private int rightRes;

public WaybillActionDialog(Context context) {
super(context);
}

@Override
public void onClick(View v) {
dismiss();
if (waybillActionListener == null) {
return;
}
switch (v.getId()) {
case R.id.ll_left:
waybillActionListener.onClickDotWanted();
break;
case R.id.ll_right:
waybillActionListener.onClickRemoveVehicle();
break;
default:
break;
}

}

@Override
protected void initContentView() {
//要求弹窗全屏,位置显示有问题,代码强制全屏
setContentView(R.layout.dialog_waybill_action);
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.width = getContext().getResources().getDisplayMetrics().widthPixels;
window.setAttributes(params);
window.setGravity(Gravity.BOTTOM);
window.setWindowAnimations(R.style.Anim_DropDownUp);
}

@Override
protected void initView() {
llLeft = (LinearLayout) findViewById(R.id.ll_left);
llRight = (LinearLayout) findViewById(R.id.ll_right);
ivPullDown = (ImageView) findViewById(R.id.btn_pull_down);
tvLeft = (TextView) findViewById(R.id.tv_left);
tvRight = (TextView) findViewById(R.id.tv_right);
ivLeft = (ImageView) findViewById(R.id.iv_left);
ivRight = (ImageView) findViewById(R.id.iv_right);
}

@Override
protected void initListener() {
ivPullDown.setOnClickListener(this);
llLeft.setOnClickListener(this);
llRight.setOnClickListener(this);
}

@Override
protected void initData() {
if (!StringUtils.isEmpty(leftText)) {
tvLeft.setText(leftText);
}
if (!StringUtils.isEmpty(rightText)) {
tvRight.setText(rightText);
}

if (leftRes > 0) {
ivLeft.setImageResource(leftRes);
}
if (rightRes > 0) {
ivRight.setImageResource(rightRes);
}
setCanceledOnTouchOutside(false);
}

public void setWaybillActionListener(OnWaybillActionListener onPopWindowDialogListener) {
this.waybillActionListener = onPopWindowDialogListener;
}

public interface OnWaybillActionListener {
void onClickDotWanted();

void onClickRemoveVehicle();
}

/**
* 设置左边图片显示
*
* @param leftRes
*/

public void setLeftImage(int leftRes) {
this.leftRes = leftRes;
}

/**
* 设置左边文字显示
*
* @param text
*/

public void setLeftText(String text) {
leftText = text;
}

/**
* 设置右边图片显示
*
* @param rightRes
*/

public void setRightImage(int rightRes) {
this.rightRes = rightRes;
}

/**
* 设置右边文字显示
*
* @param text
*/

public void setRightText(String text) {
rightText = text;
}


}

4. 显示弹框,部分核心代码

“`

private void showWaybillActionDialog() {
WaybillActionDialog dialog = new WaybillActionDialog(getActivity());
dialog.setRightText(getString(R.string.from_package_delete));
dialog.show();

dialog.setWaybillActionListener(new WaybillActionDialog.OnWaybillActionListener() {
@Override
public void onClickDotWanted() {
showDotWantedActivity();
}

@Override
public void onClickRemoveVehicle() {
showPackedFromRemoveActivity();
}
});
}

“`