自定义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

相关文章

使用雪花算法产生id导致前端精度缺失问题解决方案

《使用雪花算法产生id导致前端精度缺失问题解决方案》雪花算法由Twitter提出,设计目的是生成唯一的、递增的ID,下面:本文主要介绍使用雪花算法产生id导致前端精度缺失问题的解决方案,文中通过代... 目录一、问题根源二、解决方案1. 全局配置Jackson序列化规则2. 实体类必须使用Long封装类3.

Idea插件MybatisX失效的问题解决

《Idea插件MybatisX失效的问题解决》:本文主要介绍Idea插件MybatisX失效的问题解决,详细的介绍了4种问题的解决方法,具有一定的参考价值,感兴趣的可以了解一下... 目录一、重启idea或者卸载重装MyBATis插件(无需多言)二、检查.XML文件与.Java(该文件后缀Idea可能会隐藏

Nginx 访问 /root/下 403 Forbidden问题解决

《Nginx访问/root/下403Forbidden问题解决》在使用Nginx作为Web服务器时,可能会遇到403Forbidden错误,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录解决 Nginx 访问 /root/test/1.html 403 Forbidden 问题问题复现Ng

Python的pip在命令行无法使用问题的解决方法

《Python的pip在命令行无法使用问题的解决方法》PIP是通用的Python包管理工具,提供了对Python包的查找、下载、安装、卸载、更新等功能,安装诸如Pygame、Pymysql等Pyt... 目录前言一. pip是什么?二. 为什么无法使用?1. 当我们在命令行输入指令并回车时,一般主要是出现以

Nginx部署React项目时重定向循环问题的解决方案

《Nginx部署React项目时重定向循环问题的解决方案》Nginx在处理React项目请求时出现重定向循环,通常是由于`try_files`配置错误或`root`路径配置不当导致的,本文给大家详细介... 目录问题原因1. try_files 配置错误2. root 路径错误解决方法1. 检查 try_f

Python解决雅努斯问题实例方案详解

《Python解决雅努斯问题实例方案详解》:本文主要介绍Python解决雅努斯问题实例方案,雅努斯问题是指AI生成的3D对象在不同视角下出现不一致性的问题,即从不同角度看物体时,物体的形状会出现不... 目录一、雅努斯简介二、雅努斯问题三、示例代码四、解决方案五、完整解决方案一、雅努斯简介雅努斯(Janu

MySQL索引失效问题及解决方案

《MySQL索引失效问题及解决方案》:本文主要介绍MySQL索引失效问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql索引失效一、概要二、常见的导致MpythonySQL索引失效的原因三、如何诊断MySQL索引失效四、如何解决MySQL索引失

一文教你如何解决Python开发总是import出错的问题

《一文教你如何解决Python开发总是import出错的问题》经常朋友碰到Python开发的过程中import包报错的问题,所以本文将和大家介绍一下可编辑安装(EditableInstall)模式,可... 目录摘要1. 可编辑安装(Editable Install)模式到底在解决什么问题?2. 原理3.

Redis中的数据一致性问题以及解决方案

《Redis中的数据一致性问题以及解决方案》:本文主要介绍Redis中的数据一致性问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Redis 数据一致性问题的产生1. 单节点环境的一致性问题2. 网络分区和宕机3. 并发写入导致的脏数据4. 持

vscode不能打开终端问题的解决办法

《vscode不能打开终端问题的解决办法》:本文主要介绍vscode不能打开终端问题的解决办法,问题的根源是Windows的安全软件限制了PowerShell的运行,而VSCode默认使用Powe... 遇到vscode不能打开终端问题,一直以为是安全软件限制问题,也没搜到解决方案,因为影响也不大,就没有管