自定义Dialog以及Dialog的相关问题

2024-08-26 10:08
文章标签 问题 自定义 相关 dialog

本文主要是介绍自定义Dialog以及Dialog的相关问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

以前遇到过这些问题但是我都没有好好总结下以至于今天有遇到,但是忘了所以有浪费了我的一些时间,所以这次记下来,希望下一次遇到同样的问题可以快速解决。

刚开始我使用了AlertDialog.Bulder但是setView()的时候第一次是可以显示的,但是接着打开就报错说必须remoview()什么的,纠结很久,总以为能解决

但是最后还是没解决所以换一个思路就对了。

dialog有几类但是都不灵活有时候需要我们自定义dialog才能满足需求


1.dialog_report.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
     >


    <RelativeLayout
        android:id="@+id/set_titlebar"
        style="@style/title_style"
        android:layout_alignParentTop="true" >


        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/report_title"
            android:textColor="@color/white"
            android:textSize="@dimen/font16" />
    </RelativeLayout>


    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/set_titlebar"
        android:fillViewport="true"
         >


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >


            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="top"
                android:hint="@string/report_write_tip"
                android:inputType="textMultiLine"
                android:minHeight="200dp" >


            </EditText>


        </RelativeLayout>


    </ScrollView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/scrollView1"
        android:layout_centerHorizontal="true" >
        <Button 
            android:id="@+id/reportSubmit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/report_submit"
            android:layout_weight="1"
            />
        <Button 
            android:id="@+id/reportGiveUp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/report_giveup"
            android:layout_weight="1"
            />
    </LinearLayout>


</RelativeLayout>

2.style文件

<!-- 设置无标题 -->
    <style name="my_dialog_style" parent="android:style/Theme.Dialog">
   <item name="android:windowNoTitle">true</item>
    </style>
 

3.使用

        /**
* 初始化举报dialog
*/
private void initReportDialog() {
dialog=new Dialog(this,R.style.my_dialog_style);
View dialogView=View.inflate(this, R.layout.dialog_report, null);
dialog.setContentView(dialogView);
Button reportSubmit = (Button)dialogView.findViewById(R.id.reportSubmit);
Button reportGiveUp = (Button)dialogView.findViewById(R.id.reportGiveUp);
reportSubmit.setOnClickListener(submitListener());
reportGiveUp.setOnClickListener(giveUpListener());

}



/**
* 放弃按钮监听
* @return
*/
private OnClickListener giveUpListener() {
return new OnClickListener() {


@Override
public void onClick(View arg0) {
dialog.dismiss();
}
};
}

/**
* 提交按钮监听
* @return
*/
private OnClickListener submitListener() {
return new OnClickListener() {

@Override
public void onClick(View arg0) {
// 处理数据

//更新UI
dialog.dismiss();

}
};

}


/**

   *调用

**/

   dialog.show();


这篇关于自定义Dialog以及Dialog的相关问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1108255

相关文章

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并

怎样通过分析GC日志来定位Java进程的内存问题

《怎样通过分析GC日志来定位Java进程的内存问题》:本文主要介绍怎样通过分析GC日志来定位Java进程的内存问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、GC 日志基础配置1. 启用详细 GC 日志2. 不同收集器的日志格式二、关键指标与分析维度1.

Java 线程安全与 volatile与单例模式问题及解决方案

《Java线程安全与volatile与单例模式问题及解决方案》文章主要讲解线程安全问题的五个成因(调度随机、变量修改、非原子操作、内存可见性、指令重排序)及解决方案,强调使用volatile关键字... 目录什么是线程安全线程安全问题的产生与解决方案线程的调度是随机的多个线程对同一个变量进行修改线程的修改操

Redis出现中文乱码的问题及解决

《Redis出现中文乱码的问题及解决》:本文主要介绍Redis出现中文乱码的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 问题的产生2China编程. 问题的解决redihttp://www.chinasem.cns数据进制问题的解决中文乱码问题解决总结