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 ...
随机推荐
- windows 数据类型转换为 dotnet 数据类型
Windows Data Type .NET Data Type BOOL, BOOLEAN Boolean or Int32 BSTR String BYTE Byte CHAR Char DOUB ...
- Retrofit的使用
参照文档:http://gank.io/post/56e80c2c677659311bed9841 一.创建Retrofit mRetrofit = new Retrofit.Builder() .b ...
- Python之路第八天,基础(10)-异常处理
异常处理 1. 异常基础 python3 try: pass except Exception as ex: pass while True: num1 = input('num1:') num2 = ...
- 1003 Crashing Balloon
考察DFS的应用,判断两个数的因子. #include <stdio.h> int f1,f2; void DFS(int m,int n,int k){ ){ f2=; ) f1=; } ...
- python学习之day11
目录 SqlAlchemy 外键 SqlAlechemy SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是 ...
- 你应该知道的CSS文字大小单位PX、EM、PT[转]
摘要: 这里引用的是Jorux的“95%的中国网站需要重写CSS”的文章, 题目有点吓人,但是确实是现在国内网页制作方面的一些缺陷.我一直也搞不清楚px与em之间的关系和特点,看过以后确实收获很大.平 ...
- 深入浅出畅谈Zigbee
ZigBee采用802.15.4标准作为其对等通信的基础.该标准由ZigBee联盟(ZigBee Alliance)开发并管理.ZigBee Alliance是一家投资于该标准并在无线领域进行推广的联 ...
- 网路流程图 TCP/IP
- C Statements
1,while((ch = getchar()) != EOF){ putchar(ch);}2,while((ch=getchar()) != EOF){ if(ch < '0' ...
- #include <boost/regex.hpp>
boost C++的正则表达式库boost.regex可以应用正则表达式于C++.正则表达式大大减轻了搜索特定模式字符串的负担,在很多语言中都是强大的功能. boost.regex库中两个最重要的类是 ...