位置: 编程技术 - 正文

AlertDialog自定义布局(自定义dialogfragment)

编辑:rootadmin

推荐整理分享AlertDialog自定义布局(自定义dialogfragment),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:自定义dialogfragment,alertdialog自定义输入,alertdialog自定义view,自定义dialogfragment,自定义alert弹出框,alertdialog自定义输入,alertdialog自定义输入,alertdialog自定义输入,内容如对您有帮助,希望把文章链接给更多的朋友!

AlertDialog自定义布局

activity调用

private void showAlertDialog() {final AlertDialogUtil dialog = new AlertDialogUtil(this, false, null); // false代表必须点击"确定"其它不可以点击不消失,true点击其它也消失 dialog.setMessage("您尚未登录"); dialog.setBtnPositiveValue("确定"); dialog.setPositiveClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); dialog.setBtnNegativeValue("取消"); dialog.setNegativeClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub } });

dialog.show();

}

AlertDialog自定义布局(自定义dialogfragment)

AlertDialogUtil工具类

public class AlertDialogUtil extends AlertDialog { private Button btnPositive, btnNegative; private TextView tvMessage; private String message; private String btnPositiveValue, btnNegativeValue; private View.OnClickListener positiveListener, negativeListener; public AlertDialogUtil(Context context, boolean cancelable, OnCancelListener cancelListener) { super(context, cancelable, cancelListener); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_confirm); initView(); } public void setMessage(String message) { this.message = message; } public void setBtnPositiveValue(String val) { this.btnPositiveValue = val; } public void setPositiveClickListener(View.OnClickListener listener) { this.positiveListener = listener; } public void setBtnNegativeValue(String val) { this.btnNegativeValue = val; } public void setNegativeClickListener(View.OnClickListener listener) { this.negativeListener = listener; } private void initView() { // 布局 你可以写你想要的对话框布局 btnPositive = (Button) findViewById(R.id.btn_alertDialogutil_cancel); btnNegative = (Button) findViewById(R.id.btn_alertDialogutil_confirm); tvMessage = (TextView) findViewById(R.id.textView_title_mydialog); if (isNullEmptyBlank(message)) { tvMessage.setVisibility(View.GONE); } else { this.setCancelable(cancelable); tvMessage.setText(message); } if (!(isNullEmptyBlank(btnPositiveValue))) { btnPositive.setText(btnPositiveValue); this.btnPositive.setOnClickListener(positiveListener); } if (!(isNullEmptyBlank(btnNegativeValue))) { btnNegative.setText(btnNegativeValue); this.btnNegative.setOnClickListener(negativeListener); } } private static boolean isNullEmptyBlank(String str) { if (str == null || "".equals(str) || "".equals(str.trim())) return true; return false; }}

xml布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="dp" android:layout_height="dp" android:layout_gravity="center" android:background="@drawable/feedback_edite_bg" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" > <TextView android:id="@&#;id/textView_title_mydialog" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/color_black" android:textSize="sp" > </TextView> </LinearLayout> <LinearLayout android:id="@&#;id/ll_alertDialogutil" android:layout_width="match_parent" android:layout_height="dp" android:orientation="vertical" android:visibility="gone" > <ImageView android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/color_linear" /> <LinearLayout android:layout_width="match_parent" android:layout_height="dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:orientation="horizontal" > <Button android:id="@&#;id/btn_alertDialogutil_cancel" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/color_transparent" android:textColor="@color/color_blue" android:textSize="sp" android:visibility="gone" /> <ImageView android:id="@&#;id/iv_alertDialogutil" android:layout_width="1dp" android:layout_height="match_parent" android:background="@color/color_linear" android:visibility="gone" /> <Button android:id="@&#;id/btn_alertDialogutil_confirm" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/color_transparent" android:textColor="@color/color_blue" android:textSize="sp" android:visibility="gone" /> </LinearLayout> </LinearLayout></LinearLayout>

Android常用工具类(收藏) Android常用工具类主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java。目前包括(HttpUtils、DownloadManagerPro、ShellUtils、PackageUtils、PreferencesUt

android系统自带actionbar总结 android不同的版本引入的actionbar有差异,现总结如下一、在support.v7包中引入布局使用onCreateOptionsMenu方法中的参数:inflateimportandroid.support.v7.app.ActionBarActiv

android最基本的lsitvew实现下拉刷新,上拉加载更多的demo 接着上次来讲,这次来动手写一下listview的下拉刷新功能和上拉加载更多功能。当然google在android4.0以上的API里面的提供了一个可以下拉加载更多的控件

本文链接地址:https://www.jiuchutong.com/biancheng/378201.html 转载请保留说明!

上一篇:android javascript 混淆配置。

下一篇:Android常用工具类(收藏)(android工具包)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络