android Dialog 自定义 继承Dialog基类_继承dialog类,新建自定义的对话框类dialogpro-程序员宅基地

技术标签: AMP  android  android menu user  adaptiveskindetector  

效果图:

步骤:

1、创建对话框的布局文件

复制代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
      <!-- 标题栏 -->
      <LinearLayout
          android:id="@+id/dlg_priority_titlebar"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true">
          <ImageView
            android:src="@drawable/star_gray"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dip"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="选择任务优先级"
            android:layout_gravity="center_vertical"/>
      </LinearLayout>
      <!-- 任务优先级 -->
      <ListView
          android:id="@+id/dlg_priority_lvw"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/dlg_priority_titlebar"
          android:background="@drawable/layout_home_bg">
      </ListView>     
</RelativeLayout>
复制代码

2、因为该布局中使用了自定义的ListView,所以再为ListView创建布局文件

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageView
          android:id="@+id/list_priority_img"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical"
          android:layout_margin="5dip"        
          />
    <TextView
         android:id="@+id/list_priority_value"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
         android:textSize="28dip"
         android:textColor="@drawable/black"/>
</LinearLayout>
复制代码

3、创建自定义Dialog类PriorityDlg继承自Dialog

复制代码
public class PriorityDlg extends Dialog {
    
    private Context context;
    private ListView dlg_priority_lvw = null;

    public PriorityDlg(Context context) {
        super(context);
        this.context = context;
        // TODO Auto-generated constructor stub
    }
    
    public PriorityDlg(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
      //设置对话框使用的布局文件
        this.setContentView(R.layout.dlg_priority);

        dlg_priority_lvw = (ListView) findViewById(R.id.dlg_priority_lvw);

        // 设置ListView的数据源
        SimpleAdapter adapter = new SimpleAdapter(context, getPriorityList(),
                R.layout.lvw_priority, new String[] { "list_priority_img",
                        "list_priority_value" }, new int[] {
                        R.id.list_priority_img, R.id.list_priority_value });
        dlg_priority_lvw.setAdapter(adapter);

        // 为ListView设置监听器
        dlg_priority_lvw
                .setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {

                    }
                });
    }

    /**
     * 得到ListView数据源
     * 
     * @return
     */
    private List<HashMap<String, Object>> getPriorityList() {
        List<HashMap<String, Object>> priorityList = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> map1 = new HashMap<String, Object>();
        map1.put("list_priority_img", R.drawable.priority_not_important);
        map1.put("list_priority_value", context.getResources().getString(
                R.string.dlg_priority_not_important));
        priorityList.add(map1);
        HashMap<String, Object> map2 = new HashMap<String, Object>();
        map2.put("list_priority_img", R.drawable.priority_general);
        map2.put("list_priority_value", context.getResources().getString(
                R.string.dlg_priority_general));
        priorityList.add(map2);
        HashMap<String, Object> map3 = new HashMap<String, Object>();
        map3.put("list_priority_img", R.drawable.priority_important);
        map3.put("list_priority_value", context.getResources().getString(
                R.string.dlg_priority_important));
        priorityList.add(map3);
        HashMap<String, Object> map4 = new HashMap<String, Object>();
        map4.put("list_priority_img", R.drawable.priority_very_important);
        map4.put("list_priority_value", context.getResources().getString(
                R.string.dlg_priority_very_important));
        priorityList.add(map4);

        return priorityList;
    }

}
复制代码

4、创建自定义对话框

PriorityDlg dlg = new PriorityDlg(SimpleTaskActivity.this, R.style.dlg_priority);
return dlg;

这里的R.style.dlg_priority设置了对话框使用的样式文件,只是让对话框去掉标题栏,当然你也可以通过代码来完成这种效果:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- 对话框样式 -->
    <style name="dlg_priority" parent="@android:Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>
复制代码

到这里自定义对话框的创建就结束了,想要什么样子的对话框完全凭你自己的想像。


版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xqw11111/article/details/39973601

智能推荐

Android Studio一个项目引入另一个项目作为依赖Libary(富文本编辑器版本)_android 如果引用一个项目作为lib-程序员宅基地

文章浏览阅读975次。文章目录一、源码,详见地址二、实践篇1、导入依赖项目​2、配置添加依赖项目3、把依赖项目设置为兼容的library(错误解决)声明:本教程不收取任何费用,欢迎转载,尊重作者劳动成果,不得用于商业用途,侵权必究!!!大概是在去年12月份写了一篇这样的文章,最近参照来看发现看的有些费劲,因为当时用的Markdown编辑器所以编辑和排版都相对比较麻烦不好观看,所以决定重新写一..._android 如果引用一个项目作为lib

Quartz_quartz毕设参考文献-程序员宅基地

文章浏览阅读97次。这里是修真院后端小课堂,每篇分享文从八个方面深度解析后端知识/技能,本篇分享的是:【Quartz】【修真院Java小课堂】任务调度-Quartz开场语:大家好,我是IT修真院北京分院第32期的学员廖友,一枚正直纯洁善良的Java程序员,今天给大家分享一下,修真院官网Java任务十中的知识点——任务调度-Quartz一、背景介绍:1、任务调度概念任务调度是指基于给定时间点,给定时间间..._quartz毕设参考文献

linux系统下无法用SecureCRT及putty工具远程登录系统方法-程序员宅基地

文章浏览阅读191次。一般情况下,我们安装好了linux系统,都希望通过工具能够进行远程管理,这样可以方便许多,但是有时候却无法通过这些工具连接,主要是由于我们没有安装远程的服务,如ssh及telnet这2个服务!命令方式安装:sudo apt-get install ssh 安装telnet方法:sudo apt-get install telnet Telnet..._linux不能通过工具访问远程

The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You mu-程序员宅基地

文章浏览阅读174次。在做springboot连接数据库时:方案1:在项目代码-数据库连接URL后,加上 (注意大小写必须一致)?serverTimezone=UTC方案2:在mysql中设置时区,默认为SYSTEM set global time_zone='+8:00'错误原因:使用了Mysql Connector/J 6.x以上的版本,然set global time_zone='+8:0...

解决经过zuul网关,文件上传失败问题_zuul网关 file not allowed to upload!-程序员宅基地

文章浏览阅读4.1k次。在Spring Cloud Zuul中,Zuul本身有几个核心过滤器源码如下:其中 ServletDetectionFilter优先级最高 为-3 ,所以最先执行,这个核心过滤器只是做了一个判断当前请求是通过Spring的DispatcherServlet处理运行,还是通过ZuulServlet来处理运行,并把结果放回上下文中。一般般情况下,发送到API网关的外部请求都会被Spring..._zuul网关 file not allowed to upload!

使用Python 进行串口通信过程记录——PySerial安装_phthon 脱机安装串口模块-程序员宅基地

文章浏览阅读3.6k次。该文章的前提是已安装Python(楼主安装版本为64bit的3.7版本),使用PySerial模块,该模块安装前可先安装pip(推荐安装,还可以用于安装其他模块,使用方便)一、安装PIP1、下载安装包,地址为:https://pypi.org/project/pip/#files2、下载完成后将其解压到python目录下:随后,cmd进入该目录下,并进入到pip-19.0..._phthon 脱机安装串口模块

随便推点

在python moviepy中编辑后的视频没有声音的解决方案_moviepy 音频不加载-程序员宅基地

文章浏览阅读3.2k次。据说是mac下才会发生,其实不是的,和播放器的音频解码方式有关,大家在调用write_videofile函数时加上参数audio_codec="aac",改变下声道编码即可_moviepy 音频不加载

无法打开文件MSVCRTD.lib VS2017_无法打开文件“msvcrtd.lib”-程序员宅基地

文章浏览阅读1.9k次。_无法打开文件“msvcrtd.lib”

完善动态so加载库-程序员宅基地

文章浏览阅读96次。以上代码包括实验代码,都能在这里找到SillyBoy作者:Pika链接:https://juejin.cn/post/7227029203656867899来源:稀土掘金著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。_动态so

OPENSSL之计算SHA1散列值_基于openssl实现sha1算法哈希运算-程序员宅基地

文章浏览阅读1k次。今天遇到了sha的相关函数的应用,随手收集了点有用的资料,以后在看。。。。。。。HA1散列函数是很常用的散列函数,它产生160bit(20字节)长度的散列值。今天,我就来介绍利用OpenSSL现成的API来计算数据的SHA1散列值。先来看OpenSSL的相关API声明: #include unsigned char *SHA_基于openssl实现sha1算法哈希运算

【Unity 24】Unity中的向量点乘和叉乘的应用_3d游戏中向量叉乘-程序员宅基地

文章浏览阅读4.6k次,点赞10次,收藏32次。PS:本系列笔记将会记录我此次在北京学习Unity开发的总体过程,方便后期写总结,笔记为日更。笔记内容均为 自己理解,不保证每个都对点乘求角度,叉乘求方向比如敌人再附近,点乘可以求出玩家面朝方向和敌人方向的夹角,叉乘可以得出左转还是右转更好的转向敌人Part 1 点乘:数学上的 点乘为 a * b = |a| * |b| * cos(Θ) Unity中的点乘也是如此 点乘结果为 ..._3d游戏中向量叉乘

poj 3468 A Simple Problem with Integers(线段树)(第二部分 成段更新,区间求和)-程序员宅基地

文章浏览阅读262次。题目链接:http://poj.org/problem?id=3468题目大意:给出n个数的数值Q是对区间a,b的求和C是对区间a,b内的所有数都加上c思路:成段更新,需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的时候#include#include#include#include#inc

推荐文章

热门文章

相关标签