Android自定义dialog 自下往上弹出的实例代码

具体代码如下所示:

package com.example.idmin.myapplication.wiget;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.example.idmin.myapplication.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class BottomDialog extends Dialog {
  @BindView(R.id.chang)
  TextView chang;
  @BindView(R.id.exite)
  TextView exite;
  @BindView(R.id.cancel)
  TextView cancel;
  private BottomDialogAlertListener listener;
  private Object param;
  private String text1;
  private String text2;
  private String cansleText;
  public BottomDialog(Context context, BottomDialogAlertListener listener, Object param, String text1, String text2, String cansleText) {
    super(context, R.style.dialog1);
    this.listener = listener;
    this.param = param;
    this.text1 = text1;
    this.text2 = text2;
    this.cansleText = cansleText;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog_bottom);
    ButterKnife.bind(this);
    setCancelable(false);
    setCanceledOnTouchOutside(false);
    if (listener != null) {
      listener.onDialogCreate(this, param);
    }
    setView();
  }
  private void setView() {
    chang.setText(text1);
    exite.setText(text2);
    cancel.setText(cansleText);
  }
  @OnClick({R.id.chang, R.id.exite, R.id.cancel})
  public void onViewClicked(View view) {
    switch (view.getId()) {
      case R.id.chang:
        if (listener != null) {
          listener.chenge(this,param);
        }
        break;
      case R.id.exite:
        if (listener != null) {
          listener.excite(this,param);
        }
        break;
      case R.id.cancel:
        if (listener != null) {
          listener.cancel(this,param);
        }
        break;
    }
  }
  @Override
  public void show() {
    super.show();
    /**
     * 设置宽度全屏,要设置在show的后面
     */
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.gravity = Gravity.BOTTOM;
    layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    getWindow().getDecorView().setPadding(0, 0, 0, 0);
    getWindow().setAttributes(layoutParams);
  }
}
 

 

 


  

 


  

总结

以上所述是小编给大家介绍的Android自定义dialog 自下往上弹出的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

你可能感兴趣的:(Android自定义dialog 自下往上弹出的实例代码)