android 自定义AlertDialog
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的更多相关文章
- Android 自定义AlertDialog退出对话框
Android 自定义AlertDialog退出对话框 转 https://blog.csdn.net/wkh11/article/details/53081634在项目中很多时候会出现点击返回键出现 ...
- Android 自定义AlertDialog的实现
Android默认的AlertDialog太单调,我们可以通过继承原生的Dialog来实现自定义的Dialog. 本文的自定义Dialog和原生的AlertDialog的创建方式类似,通过一个静态Bu ...
- Android自定义AlertDialog
常见的一种方法: [html] view plaincopyprint? AlertDialog.Builder builder; AlertDialog alertDialog; LayoutInf ...
- android 自定义AlertDialog(一段)
java: final AlertDialog dialog = new AlertDialog.Builder(mContext) .create(); dialog.setCancelable(f ...
- Android 自定义AlertDialog(退出提示框)
有时候我们需要在游戏或应用中用一些符合我们样式的提示框(AlertDialog) 以下是我在开发一个小游戏中总结出来的.希望对大家有用. 先上效果图: 下面是用到的背景图或按钮的图片 经过查找资料和参 ...
- Android 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏
private void showMyDialog(int layoutId){ AlertDialog myDialog = new AlertDialog.Builder(context).cre ...
- android 自定义alertdialog和取消dialog
看代码: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle ...
- Android之自定义AlertDialog和PopupWindow实现(仿微信Dialog)
我们知道,在很多时候,我们都不用Android内置的一些控件,而是自己自定义一些自己想要的控件,这样显得界面更美观. 今天主要是讲自定义AlertDialog和popupWindow的使用,在很多需求 ...
- Xamarin.Android 记事本(二)自定义AlertDialog
导读 1.自定义一个AlertDialog 2.添加一条数据 正文 记事本应当有一个添加功能,这里我打算在右上角放一个item,然后点击这个item弹出一个对话框,输入名称,点击确定跳转到另一个act ...
随机推荐
- ORACLE DUAL表详解 .
今天在戴明明同学的QQ空间里看到篇不错的关于DUAL表的文章,自己平时也时而会用到,可是没有系统的学习过,借这个机会学习学习~ ==================================== ...
- Immediate Decodability(字典树)
Immediate Decodability Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- KNN(k-nearest neighbor的缩写)又叫最近邻算法
KNN(k-nearest neighbor的缩写)又叫最近邻算法 机器学习笔记--KNN算法1 前言 Hello ,everyone. 我是小花.大四毕业,留在学校有点事情,就在这里和大家吹吹我们的 ...
- delphi 获取北京时间(使用XMLHTTP获取百度的时间,WebBrowser获取www.timedate.cn的时间)
方法一: uses ComObj, DateUtils; function GetInternetTime: string; var XmlHttp: OleVariant; datetxt: str ...
- 【javascript 对日期的扩展 Format\addDays】
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(H).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- 2.5 Local Methods in High Dimensions
curse of dimensionality 输入在p维立方体中符合均匀分布,如果需要覆盖比例r的体积,需要每个维度上\(e_p(r)=r^{1/p}\) \(e_{10}(0.01)=0.63,e ...
- poj2301
Beat the Spread! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17794 Accepted: 8484 ...
- 安装 SQL Server 2008 R2 的硬件和软件要求(转)
以下各部分列出了安装和运行 SQL Server 2008 R2 的最低硬件和软件要求.有关 SharePoint 集成模式下的 Analysis Services 的要求的详细信息,请参阅硬件和软件 ...
- 关于” fatal error C1010: unexpected end of file while looking forprecompiled header directive”问题
其中文意思是:致命错误C1010:意想不到的文件结束而寻找预编译头文件的指令错误执行cl exe. 经过多次的查找,终于解决这问题 方法一: 在头文件中加“#include "stdafx. ...
- 网易云课堂_C++程序设计入门(上)_第5单元:万类霜天竞自由 – 对象和类的更多内容_第5单元作业【4】 - 在线编程(难度:难)
第5单元作业[4] - 在线编程(难度:难) 查看帮助 返回 温馨提示: 1.本次作业属于Online Judge题目,提交后由系统即时判分. 2.学生可以在作业截止时间之前不限次数提交答案,系 ...