android 自定义AlertDialog

时间:2022-10-25 21:55:23

xml:

alter_dialog_two

<?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:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:background="@drawable/line_gray_cancel"
android:orientation="vertical" > <TextView
android:id="@+id/tv_alter_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text=""
android:textColor="@android:color/black"
android:textSize="@dimen/dialog_font" /> <View
style="@style/LineHorizontal.Gray_d8"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal" > <Button
android:id="@+id/btn_two_cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=""
android:background="@drawable/sel_alter_yes_bg"
android:gravity="center"
android:text="@string/cancel"
android:textColor="@color/blue_03"
android:textSize="@dimen/dialog_font" /> <View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="1dp"
android:background="@color/gray_d8" /> <Button
android:id="@+id/btn_two_ok"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=""
android:background="@drawable/sel_alter_no_bg"
android:gravity="center"
android:text="@string/ok"
android:textColor="@color/blue_03"
android:textSize="@dimen/dialog_font" />
</LinearLayout>
</LinearLayout> </LinearLayout>
TwoBtnAlterDialog
package com.android.hcframe.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView; import com.android.hcframe.R; public class TwoBtnAlterDialog extends Dialog { private static TwoBtnAlterDialog twoBtnDialog = null;
public static TextView tvAlterContent;
public static Button btn_ok, btn_cancel; public TwoBtnAlterDialog(Context context) {
super(context);
} public TwoBtnAlterDialog(Context context, int theme) {
super(context, theme);
} public static TwoBtnAlterDialog createDialog(Context context,String msg) {
twoBtnDialog = new TwoBtnAlterDialog(context, R.style.CustomAlterDialog);
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.alter_dialog_two, null);
twoBtnDialog.setContentView(view);
Window win = twoBtnDialog.getWindow();
win.getAttributes().gravity = Gravity.CENTER;
// win.setWindowAnimations(R.style.dialogWindowAnimTop); tvAlterContent = (TextView) twoBtnDialog.findViewById(R.id.tv_alter_content);
tvAlterContent.setText(msg);
btn_ok = (Button) twoBtnDialog.findViewById(R.id.btn_two_ok);
btn_cancel = (Button) twoBtnDialog.findViewById(R.id.btn_two_cancel);
return twoBtnDialog;
} }

java调用:

 private static TwoBtnAlterDialog alterDialog;

    public static void twoBtnAlterDialog(final Context context, String msg) {
if (alterDialog == null) {
alterDialog = TwoBtnAlterDialog.createDialog(context, msg);
TwoBtnAlterDialog.btn_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, "ok", Toast.LENGTH_SHORT).show();
}
});
TwoBtnAlterDialog.btn_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, "cancel", Toast.LENGTH_SHORT).show();
}
});
alterDialog.show();
} else {
alterDialog.dismiss();
alterDialog = null;
} }

android 自定义AlertDialog的更多相关文章

  1. Android 自定义AlertDialog退出对话框

    Android 自定义AlertDialog退出对话框 转 https://blog.csdn.net/wkh11/article/details/53081634在项目中很多时候会出现点击返回键出现 ...

  2. Android 自定义AlertDialog的实现

    Android默认的AlertDialog太单调,我们可以通过继承原生的Dialog来实现自定义的Dialog. 本文的自定义Dialog和原生的AlertDialog的创建方式类似,通过一个静态Bu ...

  3. Android自定义AlertDialog

    常见的一种方法: [html] view plaincopyprint? AlertDialog.Builder builder; AlertDialog alertDialog; LayoutInf ...

  4. android 自定义AlertDialog&lpar;一段&rpar;

    java: final AlertDialog dialog = new AlertDialog.Builder(mContext) .create(); dialog.setCancelable(f ...

  5. Android 自定义AlertDialog&lpar;退出提示框&rpar;

    有时候我们需要在游戏或应用中用一些符合我们样式的提示框(AlertDialog) 以下是我在开发一个小游戏中总结出来的.希望对大家有用. 先上效果图: 下面是用到的背景图或按钮的图片 经过查找资料和参 ...

  6. Android 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏

    private void showMyDialog(int layoutId){ AlertDialog myDialog = new AlertDialog.Builder(context).cre ...

  7. android 自定义alertdialog和取消dialog

    看代码: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle ...

  8. Android之自定义AlertDialog和PopupWindow实现(仿微信Dialog)

    我们知道,在很多时候,我们都不用Android内置的一些控件,而是自己自定义一些自己想要的控件,这样显得界面更美观. 今天主要是讲自定义AlertDialog和popupWindow的使用,在很多需求 ...

  9. Xamarin&period;Android 记事本(二)自定义AlertDialog

    导读 1.自定义一个AlertDialog 2.添加一条数据 正文 记事本应当有一个添加功能,这里我打算在右上角放一个item,然后点击这个item弹出一个对话框,输入名称,点击确定跳转到另一个act ...

随机推荐

  1. c&plus;&plus; stringstream(老好用了)

    前言: 以前没有接触过stringstream这个类的时候,常用的字符串和数字转换函数就是sscanf和sprintf函数.开始的时候就觉得这两个函数应经很叼了,但是毕竟是属于c的.c++中引入了流的 ...

  2. 【leetcode❤python】 299&period; Bulls and Cows

    #-*- coding: UTF-8 -*-class Solution(object):      def getHint(self, secret, guess):          " ...

  3. Qt 日志宏

    随便写了一个日志帮助的宏,既可以如同qDebug()一般在调试时输出信息,也可以在输出文本文件 #ifndef LOG_H #define LOG_H #include <QDir> #i ...

  4. struts1、 struts2所有版本jar包下载地址大全

     jakarta-struts-1.2.2.tar.gz      30-Aug-2004 18:21   12M  jakarta-struts-1.2.2.tar.gz.asc  30-Aug-2 ...

  5. poj3349&lpar;哈希&plus;链地址法&rpar;

    给出N个六边形的6个边长,问其中是否有完全相同的两个六边形,完全相同包括边的长度和位置都要相同.边给出的顺序是逆时针或者顺时针的. 给每个6边形一个哈希值,方法是对6条边长度的平方和取模 #inclu ...

  6. centos 6&period;4 x64安装bugfree

    第一步:下载xampp-linux-1.8.1.tar.gz [root@SVNMANAGER ~]# tar -zxvf xampp-linux-1.8.1.tar.gz -C /opt [root ...

  7. Jpa 本地方式实现数据的持久化【千锋】

    Jpa本身支持多种方式的对象持久化,比如数据库方式,还有一种方式就是本地文件的方式,本文来讲解以本地方式实现的数据持久化,具体的资源大家可以参阅一下网站:http://www.objectdb.com ...

  8. arcgis api 3&period;x for js 共享干货系列之一自写算法实现地图量算工具(附源码下载)

    0.内容概览 Geometry 地图服务方式实现地图距离以及面积的量算,简单描述 arcgis api 提供的接口类 geometryEngine 实现地图距离以及面积的量算,简单描述 自定义距离以及 ...

  9. dubbo入门学习 二 RPC框架

    rpc框架解释 谁能用通俗的语言解释一下什么是 RPC 框架? - 远程过程调用协议RPC(Remote Procedure Call Protocol) 首先了解什么叫RPC,为什么要RPC,RPC ...

  10. (转) Unity3D 使用Texturepacker打包工具制作NGUI&lpar;Atlas&rpar;图集

    转自:http://www.unitymanual.com/thread-37485-1-1.html 由于NGUI AtlasMaker对打包的优化不好,容易打出很大的图集,很多部分都是浪费的,所有 ...