DialogFragment你值得拥用

Android通用DialogFragment 前言 在开发过程中,我们会经常使用对话框,为了提高开发效率,于是我使用DialogFragment封装了一个通过的对话框。 为什么使用DialogFragment 首先在使用 DialogFragment之前,我们创建对话框一般都会采用Dialog的形式,并且从编写代码的角度来看,Dialog使用起来也较为简单,但Android 官方推荐使用 DialogFragment 来代替 Dialog。 DialogFragment 有着Dialog 所没有的特性在手机配置变化,导致Activity需要重新创建时, 阅读详情

最近写了一个弹框,发现之前写弹窗方式。

  1. dialog
  2. PopupWindow

因为Android 官方推荐使用 DialogFragment,所以就尝试了一下,简直不要太好啊。

DialogFragment是基于Fragment实现的。

public class ShareGiftBag extends DialogFragment implements View.OnClickListener {

    private TextView tvTitle;
    private TextView tvBut;
    private ImageView ivPic, ivCancel;
    private Callback callback;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.common_share_giftbag_dialog, container, false);
        initView(v);
        return v;
    }

    private void initView(View v) {
        tvTitle = v.findViewById(R.id.tv_title);
        tvBut = v.findViewById(R.id.tv_but);
        ivPic = v.findViewById(R.id.iv_pic);
        ivCancel = v.findViewById(R.id.iv_cancel);
        tvBut.setOnClickListener(this);
        ivCancel.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.iv_cancel) {
            dismiss();
        } else if (id == R.id.tv_but) {
            if (callback != null) {
                callback.call("");
                ToastUtil.s("1234567890");
            }
        }
    }

    //显示信息
    public void setDataShow(String title, Callback callback) {
        this.callback = callback;
//        tvTitle.setText(title);
    }
}


<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="307dp"
    android:layout_height="300dp"
    android:layout_centerInParent="true"
    android:background="@drawable/round_corner_white_10dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="15dp"
        android:gravity="center"
        android:text="礼物分享你我他"
        android:textColor="#333333"
        android:textSize="@dimen/lyg_font_size_17sp" />

    <ImageView
        android:id="@+id/iv_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:padding="10dp"
        android:src="@drawable/icon_card_icon_close" />

    <ImageView
        android:id="@+id/iv_pic"
        android:layout_width="263dp"
        android:layout_height="179dp"
        android:layout_below="@+id/tv_title"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="7dp"
        android:layout_marginRight="22dp"
        android:src="@drawable/icon_pic_gift" />


    <TextView
        android:id="@+id/tv_but"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_below="@+id/iv_pic"
        android:layout_marginLeft="22dp"
        android:layout_marginTop="8dp"
        android:layout_marginRight="22dp"
        android:layout_marginBottom="20dp"
        android:background="@drawable/btn_share_bg_bg"
        android:gravity="center"
        android:text="分享"
        android:textColor="@color/white"
        android:textSize="18sp" />

</RelativeLayout>


Dialogfragment嵌套Viewpager 项目需要实现一个在页面底部的弹窗,里面是Viewpager实现的可以左右滑动的多页面。Viewpager其中一个页面有Listview,点其中的按钮会跳转到Viewpager另外一个子页面中,并且更新其中的内容。 首先需要实现页面底部弹窗,一开始准备使用Popupwindow + Viewpager的方法,后来搜了资料发现这里有一个android的bug,会报错“Error no vie 阅读详情

相关推荐

reactnative弹出框类似android的DialogFragment

react native 弹出框,类似android的DialogFragment

使用DialogFragment的一些感受及防踩坑经验(getActivity、getDialog为空,cancelable无效等)

前言 安卓里面创建对话框的方式其实蛮多的。Dialog、AlertDialog、DialogFragment、PopupWindow甚至Activity设置主题为Dialog也能创建对话框。

cjs1534717040的专栏 3417

封装一个通用Dialog,使用DialogFragment

封装一个通用Dialog,使用DialogFragment有很多优势。

DialogFragment 的使用和一些坑点

最近在使用 DialogFragment 的时候踩了一些坑,所以写个博客记录一下。 DialogFragment 使用起来和普通的 fragment 差不多,在普通 fragment 的基础上 DialogFragment 可以通过 show() 和 dismiss() 方法来控制显示和消失,并且自带显示的效果,相对与普通的 dialog,DialogFragment 可以支持自定义布局,使用起...

Edward_KW的博客 1万+

基于Ultralytic实现多路摄像头目标检测

基于Ultralytic实现多路摄像头目标检测前面的文章分享了单路摄像头画面的YOLO目标检测,这篇文章主要分享一下多路摄像头画面的实时YOLO目标检测。测试环境在Windows系统下进行。

qq_57674776的博客 942

GEE开发之ERA5(气温、降水、压力、风速等)数据获取和分析

前言:ERA5主要提供DAILY和MONTHLY两大类别数据,其中主要包括气温、降水、压力、风速等。

等待着冬天的风的博客 3万+

还在用Dialog吗——DialogFragment带你体验完美高效率

DialogFragment带你体验完美高效率最近研究了DialogFragment形式的dialog,发现有很多优势,与普通的dialog一起做了一些比较和总结。效果如下:最近学习弹框时发现有三种类型的可供使用, PopupWindow、dialog,DialogFragment。比如说需求: 只拦截自身所占空间部分的事件,其余空间的点击事件不处理 可以根据改变View的布局排列方式,View是

这个时代,作为程序员可能要学习小程序 3万+

【车辆仿真】从0开始建立dSPACE RT Simulink工程:CAN通信(RTICANMM方法)

【工程环境信息】:本文基于链接文章搭建SCALEXIO Rack RTPC总线节点,用于与AutoBox通信硬件:上位机:惠普台式PC(Windows 11专业版)下位机(实时机):AutoBox (DS1006)板卡:DS6342软件:本文所使用的DBC链接提示:以下是本篇文章正文内容,下面案例可供参考!!!的部分一定记得配置,其他的按需配置RTICANMM的灵活度非常高,尽可能参考Help文档,理解相应的配置内容官方有RTICANMM的样例工程,在下方路径。

winnizap的博客 2382

Android 弹窗 DialogFragment

前言 一直以来 , 做弹窗功能的时候都是使用的Dialog , 布局复杂的弹窗则使用Activity , 把背景设置成透明, 最近了解到一个DialogFragment , 发现使用起来更加方便, 也是谷歌建议的做法. 简介 DialogFragment 继承自Fragment , 所以它的用法基本跟Fragment一致 , 也包含了一些生命周期和上下文context 和 监听之类的东西. 而且...

卓原的进化之旅 7190

EDA虚拟机分享2020版本(Synopsys2020)

EDA虚拟机分享

亦安的数字小站 9193

win x64下安装oracle 12c出现[INS-30131]报错的解决方案

问题:  win x64下安装oracle 12c出现[INS-30131]报错的解决方案 安装oracle11g碰到“无法访问临时位置”的问题,详细信息如下: INS-30131] 执行安装程序验证所需的初始设置失败。 原因 - 无法访问临时位置。   操作 - 请确保当前用户具有访问临时位置所需的权限。   附加信息:  - 所有节点上的框架设置检查都失败  

一条道走到黑的GISer 1348

DialogFragment使用详解

文章目录一、前言二、DialogFragment使用2.1 DialogFragment的创建1、重写onCreateDialog()2、重写onCreateView()2.2 DialogFragment布局不生效1、setBackgroundDrawableResource 一、前言 DialogFragment是用于展示弹窗的API,与Dialog不同,DialogFragment本质上是一个Fragment,也就具有Fragment所拥有的生命周期。在使用时,更容易通过生命周期回调来管理弹窗。对于复

qq_21830869的博客 1万+

从频谱入手搞定ESD:手把手教你用示波器和频谱仪分析静电干扰(以Type-C接口为例)

本文详细介绍了如何利用示波器和频谱仪分析Type-C接口的ESD干扰问题。通过频谱特性分析、耦合路径诊断和实战测试,提供了一套完整的ESD防护方案,包括三级防护设计和器件选型建议,帮助工程师有效解决静电放电导致的系统故障。

weixin_42662293的博客 348

DialogFragment 出场动画

DialogFragment 其实就是继承fragment,用Fragment的事物进行管理 首先在onCreate中指定DialogFragment 所对应的样式 setStyle(DialogFragment.STYLE_NO_FRAME, R.style.DialogStyle); <style name="DialogStyle" parent="@android:styl...

weixin_39413778的博客 3356

多传感器融合SLAM指南:如何结合视觉与激光雷达提升建图精度

本文深入探讨了多传感器融合SLAM技术,详细解析了如何将视觉传感器与激光雷达(特别是3D激光雷达)进行深度融合以提升建图精度与鲁棒性。文章从传感器特性分析、数据同步标定、前端融合策略(松耦合与紧耦合)到后端优化与地图构建,提供了完整的实战指南,并重点介绍了V-LOAM等经典融合框架的核心思想,旨在帮助开发者构建适应复杂动态环境的高精度SLAM系统。

weixin_29056145的博客 536

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

在Fragment中调用DialogFragment

在android的官方文档中,dialogFragment的show方法是这样调用的: dialog.show(getFragmentManager(), "AddEventDialogFragment"); 但是在Fragment中是无法调用getFragmentManager()方法的。 可以用两种方法代替: dialog.show(getChildFragmentManager(), "A...

weixin_41924068的博客 3641

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Android DialogFragment总结

#.简介 DialogFragment是继承Fragment,兼具Fragment和Dialog的特点: 一方面,它具有Fragment的生命周期,可以由Activity的FragmentManager来管理器生命周期; 另一方面,其内部包含一个Dialog成员变量,可以像窗口一样展示。 ##.DialogFragment相对于Dialog的优点: Dialog的生命周期不会随着Activity生命周期变化而变化,而DialogFragment继承自Fragme...

u013914309的博客 2701

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Android之DialogFragment

DialogFragment是基于Fragment展示Dialog的窗口。对话框的控制(何时隐藏、显示、关闭)通过对应的Dialogment 的API来完成,而不是Dialog的API.          DialogFragment需要保证Fragment和Dialog的状态保持一致。它监听dialog的dissmiss event,并且去处理自己的状态。这意味着应该调用 show(Fra

行云间 1265

android dialogfragment style,Android DialogFragment 使用

简介项目里一直使用dialog,最近才发现谷歌早就推出了DialogFragment,由于平常写项目需求基本也都是继承dialog重写,发现使用DialogFragment更加方便,也是谷歌推荐替换的,所以来学习一下DialogFragment的用法。DialogFragment的基本使用使用一个DialogFragment一般我们需要重新写一个类来继承DialogFragment,DialogF...

weixin_39904612的博客 396

android dialogfragment 简单,使用DialogFragment

DialogFragment是Android3.0后引入的Fragment框架中的对传统Dialog效果用Fragment做的实现。android-support-v4兼容包中也包含了该类,所以我们可以通过导入兼容包在3.0之前的平台上使用它。Android开发文档上已经不推荐传统的Dialog使用了,而是用DialogFragment来代替。下面开始照着Android的开发文档来说说Dialog...

weixin_32121331的博客 684

[转载]详细解读DialogFragment

相信看这篇文章的人都应该知道android中的Dialog了吧,如果对于Dialog还不是很了解可以看我之前的一篇详解文章: Dialog详解:http://www.cnblogs.com/tianzhijiexian/p/3867731.html 随着Fragment这个类的引入,Google官方推荐大家使用DialogFragment来代替传统的Dialog,那么是不是说我们之前学习的Dialog知识都没有用处了呢?非也,新的fragment是来方便大家更好的管理和重用Dialog,之前的知识其..

流浪(WESTKING)的专栏 1438

Android中DialogFragment的使用

一.概述: DialogFragment是Android3.0(API 11)才出现的,它不像以前版本中生成AlertDialog一样,通过AlertDialog.Builder生成Dialog,而是在fragment中弹出Dialog的窗口,即DialogFragment是一个Fragment,而且这个fragment本身就含有一个Dialog对象。 二.创建DialogFragment:

FightFightFight的博客 1778

DialogFragment浅析

点击“奇舞移动技术”关注我们!前言Fragment是在Android 3.0提出的,为了兼容低版本,support-v4库也提供了一套Fragment 的API,这也是官...

QiwooMobile的博客 891

更好用的DialogFragment

工作中总是要用到各式各样的对话框,通常我们首先会想到的就是Dialog。在以前的时候我通常都会自定义一个Dialog,然后在里面写一个接口,让需要创建这个Dialog的界面继承这个接口,实现点击事件的监听。其中大概代码是这样的:/** * @date 创建时间: 2017/11/22 22:25 * @author zh_legendd * @Description 自定义的dialog

Code_legend的博客 920

DialogFragment 总结

DialogFragment 两种简单用法 onCreateView onCreateDialog oncreateDialog 中 dialog 不需要设置 setOnCancelListener和setOnDismissListener,针对android.app.DialogFragment会报错,java.lang.IllegalStateException: You can...

xyyh6600的博客 751
上一篇: HashMap原理解析
下一篇: Flutter简介
jhonjson
博客等级 码龄11年 220粉丝 195原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值