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(一段)

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

  5. Android 自定义AlertDialog(退出提示框)

    有时候我们需要在游戏或应用中用一些符合我们样式的提示框(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.Android 记事本(二)自定义AlertDialog

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

随机推荐

  1. nginx的请求接收流程(二)

    在ngx_http_process_request_line函数中,解析完请求行之后,如果请求行的uri里面包含了域名部分,则将其保持在请求结构的headers_in成员的server字段,heade ...

  2. C#中委托和事件

    目 录 将方法作为方法的参数 将方法绑定到委托 更好的封装性 限制类型能力 范例说明 Observer 设计模式简介 实现范例的Observer 设计模式 .NET 框架中的委托与事件 为什么委托定义 ...

  3. qt 自动完成LineEdit

    原地址:http://www.cppblog.com/biao/archive/2009/10/31/99873.html     ---------------------------------- ...

  4. Delphi调用安装驱动sys的单元

    unit SysDriver; interface uses windows, winsvc; // jwawinsvc; Type TSysDriver = class(TObject) priva ...

  5. QT:给Widget设置背景图片——设置Widget的调色板,调色板使用图片和背景色

    QT:给Widget设置背景图片 1 /*2 * set background image3 */4 QPixmap bgImages(":/images/bg.png");5 Q ...

  6. iis 回收工作进程时出错的解决办法

    第一种解决方案: iis6系统默认的工作进程回收时间是29个小时有很多问题是在回收工作进程后出现很多问题如典型的500错误等经过我做服务器的一段时间的观察大家可以不用回收工作进程而是把应用程序池的最大 ...

  7. jquery 单击table行事件和radio的选中事件冲突

    原文地址:http://zhidao.baidu.com/link?url=HER7lu4jqejWUhWQO2nq6LZ6tf7vyhPZRADSL-xaBQSF4P4yftD9vg08Ss8HF- ...

  8. sqlprofiler 常用调试方法

  9. hdu 1757 A Simple Math Problem(矩阵快速幂乘法)

    Problem Description Lele now is thinking about a simple function f(x). If x < f(x) = x. If x > ...

  10. Avoid The Lakes

    Avoid The Lakes Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...