Android - 弹出Dialog,开源至上

private TextView tvNo;

public MyDialog(Context context) {

super(context, R.style.style_my_dialog);

}

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.dialog_my);

//按空白处不能取消动画

setCanceledOnTouchOutside(true);

/** 初始化控件 */

initView();

/** 处理用户输入 */

handleUserInput();

}

private void initView() {

tvYes = (TextView) findViewById(R.id.tv_yes);

tvNo = (TextView) findViewById(R.id.tv_no);

}

private void handleUserInput() {

tvYes.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (yesOnclickListener != null) {

yesOnclickListener.onYesClick();

}

}

});

tvNo.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if (noOnclickListener != null) {

noOnclickListener.onNoClick();

}

}

});

}

/**

  • 设置取消按钮的显示内容和监听

  • @param onNoOnclickListener

*/

public void setNoOnclickListener(onNoOnclickListener onNoOnclickListener) {

this.noOnclickListener = onNoOnclickListener;

}

/**

  • 设置确定按钮的显示内容和监听

  • @param onYesOnclickListener

*/

public void setYesOnclickListener(onYesOnclickListener onYesOnclickListener) {

this.yesOnclickListener = onYesOnclickListener;

}

/**

  • 设置确定按钮和取消被点击的接口

*/

public interface onYesOnclickListener {

void onYesClick();

}

public interface onNoOnclickListener {

void onNoClick();

}

}

布局文件如下:dialog_my.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginLeft=“30dp”

android:layout_marginRight=“30dp”

android:orientation=“vertical”>

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background=“@drawable/bg_dialog_top”

android:padding=“10dp”

android:text=“提示”

android:textColor=“@color/color_white”

android:textSize=“14sp” />

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background=“@color/color_white”

android:paddingLeft=“30dp”

android:paddingRight=“30dp”

android:paddingTop=“15dp”

android:text=“欢迎访问我的CSDN博客: \nmythmayor的博客”

android:textColor=“@color/color_333333” />

<TextView

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:background=“@color/color_white”

android:paddingBottom=“15dp”

android:paddingLeft=“30dp”

android:paddingRight=“30dp”

android:paddingTop=“12dp”

android:text=“立即关注请点击确认”

android:textColor=“@color/color_333333” />

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”>

<TextView

android:id=“@+id/tv_no”

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:background=“@drawable/bg_dialog_bottom1”

android:gravity=“center”

总结

本文讲解了我对Android开发现状的一些看法,也许有些人会觉得我的观点不对,但我认为没有绝对的对与错,一切交给时间去证明吧!愿与各位坚守的同胞们互相学习,共同进步!

在这里我也分享一份自己收录整理的**Android学习PDF+架构视频+面试文档+源码笔记,还有高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料**帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值