简单dialog---带输入框/确定/取消
来源:互联网 发布:阿里云 部署爬虫 编辑:程序博客网 时间:2024/05/01 16:34
package com.hzpd.tts.ui;import android.app.Dialog;import android.content.Context;import android.content.DialogInterface;import android.view.View;import android.view.ViewGroup.LayoutParams;import com.hzpd.tts.R;/** * * Create custom Dialog windows for your application Custom dialogs rely on * custom layouts wich allow you to create and use your own look & feel. * * Under GPL v3 : http://www.gnu.org/licenses/gpl-3.0.html * * <a href="http://my.oschina.net/arthor" target="_blank" * rel="nofollow">@author</a> antoine vianey * */public class CustomDialog extends Dialog {public CustomDialog(Context context, int theme) {super(context, theme);}public CustomDialog(Context context) {super(context);}/** * Helper class for creating a custom dialog */public static class Builder {private Context context;private String title;// private String message;private String tv_heiwei_sureText;private String tv_heiwei_cancelText;private View contentView;private DialogInterface.OnClickListener tv_heiwei_sureClickListener,tv_heiwei_cancelClickListener;private CustomDialog dialog;public Builder(Context context) {this.context = context;}/** * Set the Dialog title from resource * * @param title * @return */public Builder setTitle(int title) {this.title = (String) context.getText(title);return this;}/** * Set the Dialog title from String * * @param title * @return */public Builder setTitle(String title) {this.title = title;return this;}/** * Set a custom content view for the Dialog. If a message is set, the * contentView is not added to the Dialog... * * @param v * @return */public Builder setContentView(View v) {this.contentView = v;return this;}/** * Set the positive button resource and it's listener * * @param tv_heiwei_sureText * @param listener * @return */public Builder settv_heiwei_sure(String tv_heiwei_sureText,DialogInterface.OnClickListener listener) {this.tv_heiwei_sureText = tv_heiwei_sureText;this.tv_heiwei_sureClickListener = listener;return this;}/** * Set the negative button text and it's listener * * @param tv_heiwei_cancelText * @param listener * @return */public Builder settv_heiwei_cancel(String tv_heiwei_cancelText,DialogInterface.OnClickListener listener) {this.tv_heiwei_cancelText = tv_heiwei_cancelText;this.tv_heiwei_cancelClickListener = listener;return this;}/** * Create the custom dialog */public CustomDialog create(View layout) {dialog = new CustomDialog(context, R.style.Theme_Transparent);dialog.setCanceledOnTouchOutside(false);dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));dialog.setContentView(layout);return dialog;}}}
// 在页面中加入
private void addDialog() {CustomDialog.Builder customBuilder = new CustomDialog.Builder(HeightWeightActivity.this);LayoutInflater inflater = (LayoutInflater) HeightWeightActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);View layout = inflater.inflate(R.layout.dialog_height_weight, null);dialog = customBuilder.create(layout);TextView tv_heiwei_cancel = (TextView) layout.findViewById(R.id.tv_heiwei_cancel);TextView tv_heiwei_sure = (TextView) layout.findViewById(R.id.tv_heiwei_sure);et_myheight = (EditText) layout.findViewById(R.id.et_myheight);et_myweight = (EditText) layout.findViewById(R.id.et_myweight);tv_heiwei_cancel.setOnClickListener(this);tv_heiwei_sure.setOnClickListener(this);dialog.show();dialog.getWindow().setLayout(width, LayoutParams.WRAP_CONTENT); // 设置Dialog大小要在show()之后否则没效果}
// 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="match_parent" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/dialog_bg" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="请输入" android:textColor="#4c4c4c" android:textSize="16sp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#f1f1f1" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="身高:" android:textColor="#4c4c4c" android:textSize="16sp" /> <EditText android:id="@+id/et_myheight" android:layout_width="70dp" android:layout_height="30dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:background="@drawable/et_danbai_bg" android:numeric="decimal" android:singleLine="true" /> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="cm" android:textColor="#4c4c4c" android:textSize="16sp" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="体重:" android:textColor="#4c4c4c" android:textSize="16sp" /> <EditText android:id="@+id/et_myweight" android:layout_width="70dp" android:layout_height="30dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:background="@drawable/et_danbai_bg" android:numeric="decimal" android:singleLine="true" /> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="kg" android:textColor="#4c4c4c" android:textSize="16sp" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#f1f1f1" /> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" > <TextView android:id="@+id/tv_heiwei_cancel" android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:gravity="center" android:text="取消" android:textColor="#4c4c4c" android:textSize="16sp" /> <TextView android:id="@+id/tv_heiwei_sure" android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:gravity="center" android:text="确定" android:textColor="#19c0be" android:textSize="16sp" /> </LinearLayout> </LinearLayout></LinearLayout>
0 0
- 简单dialog---带输入框/确定/取消
- android带输入框的Dialog
- Android带输入框的dialog
- 带输入的Dialog
- 设计文本框(输入密码,确定,取消)
- Dialog合集,全都不带图片(确定取消对话框、单选对话框、多选对话框、进度条对话框、带进度的进度条对话框)
- 带输入文本框的Dialog
- 底部弹出带输入dialog
- 28-Dialog点击选择确定,取消,显示在TextView中
- 布局平分,中间有竖线,如dialog里取消确定
- 带输入框DIalog自动弹出软键盘
- 根据条件,弹出带确定取消的对话框.
- 安卓单选对话框之带确定和取消按钮
- Android 带输入框圆角Dialog--EditDialog
- Android 带输入框圆角Dialog--EditDialog
- Android自定义Dialog带分隔的8位输入框按钮回调输入值
- 弹出一个带确认和取消的dialog
- window.prompt提示框点击取消后返回的是"",点击确定后返回的是用户输入内容。
- C# XML文件的一些操作,增删改查
- Go-Servers
- openstack安装部署——前言&规划
- 习大大语录--杭州峰会G20
- 【linux】【inout】之 文件编码转换
- 简单dialog---带输入框/确定/取消
- 安装php-soap
- Android Studio插件推荐-GsonFormat,ButterKnifeZelezny
- expdp 导出报错 ORA-39006: ORA-39065: ORA-04063: ORA-06508: ORA-39097: ORA-01403: ORA-39097:
- C#与MATLAB混合编程
- 使用相关性寻找影响某一传感器变化的因素
- CSU1805(BEST theorem,定理题)
- csu 1809 Parenthesis
- 数据结构-栈与队列