今天遇到一个大难题哦,不过有大牛一眼就瞄出来了,然后就解决了,AlertDialog和Dialog自定义后圆角的处理,如果你跟我一样没有看到这些细节的话就栽了,用AlertDialog不能使得圆角背景透明化,所以要用Dialog处理才行,也就是下面的方法。

Dialog:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
private static Dialog mDialog;
    // 加载gridview中的item的xml方法
    public static View getView(Context context, int layoutId) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(layoutId, null);
        return layout;
    }
/**
     * 显示自定义对话框
     
     * @param context
     * @param message
     * @param listener
     */
    public static void showDialog(final Context context, String message,
            final IAlertDialogButtonListener listener) {
        View dialogView = null;
        // Dialog.Builder builder = new Builder(context,
        // R.style.Theme_Transparent);
        mDialog = new Dialog(context, R.style.Theme_Transparent);
        dialogView = getView(context, R.layout.dialog_view);
        Button btn_ok = (Button) dialogView.findViewById(R.id.btn_ok);
        Button btn_cancel = (Button) dialogView.findViewById(R.id.btn_cancel);
        TextView txt_dailog_message = (TextView) dialogView
                .findViewById(R.id.txt_dailog_message);
        txt_dailog_message.setText(message);
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // 关闭dialog
                if (mDialog != null) {
                    mDialog.cancel();
                }
                // 事件回调
                if (listener != null) {
                    listener.onClick();
                }
                // 播放音效
                // MyPlayer.playTone(context, MyPlayer.INDEX_STONE_ENTER);
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // 关闭dialog
                if (mDialog != null) {
                    mDialog.cancel();
                }
                // 播放音效
                // MyPlayer.playTone(context, MyPlayer.INDEX_STONE_CANCEL);
            }
        });
        // 为dialog设置View
        // builder.setView(dialogView);
        mDialog.setContentView(dialogView);
        // mDialog = builder.create();
        mDialog.show();
    }
}

AlertDialog:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
     * 显示自定义对话框
     
     * @param context
     * @param message
     * @param listener
     */
    public static void showDialog(final Context context, String message,
            final IAlertDialogButtonListener listener) {
        View dialogView = null;
        AlertDialog.Builder builder = new Builder(context,
                R.style.Theme_Transparent);
        dialogView = getView(context, R.layout.dialog_view);
        ImageButton btn_ok = (ImageButton) dialogView.findViewById(R.id.btn_ok);
        ImageButton btn_cancel = (ImageButton) dialogView
                .findViewById(R.id.btn_cancel);
        TextView txt_dailog_message = (TextView) dialogView
                .findViewById(R.id.txt_dailog_message);
        txt_dailog_message.setText(message);
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // 关闭dialog
                if (mAlertDialog != null) {
                    mAlertDialog.cancel();
                }
                // 事件回调
                if (listener != null) {
                    listener.onClick();
                }
                // 播放音效
                MyPlayer.playTone(context, MyPlayer.INDEX_STONE_ENTER);
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // 关闭dialog
                if (mAlertDialog != null) {
                    mAlertDialog.cancel();
                }
                // 播放音效
                MyPlayer.playTone(context, MyPlayer.INDEX_STONE_CANCEL);
            }
        });
        // 为dialog设置View
        builder.setView(dialogView);
        mAlertDialog = builder.create();
        mAlertDialog.show();
    }

af_dialog_background圆角:

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#3C4856" />
    <corners
       android:bottomLeftRadius="0.1dp"
       android:bottomRightRadius="0.1dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" />
</shape>

dialog_view:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/af_dialog_background"
        android:orientation="vertical" >
        <TextView
            style="@style/TextViewStyle_aboutus"
            android:layout_gravity="left"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:text="@string/af_logo_10_dialog_title"
            android:textColor="@color/white4"
            android:textSize="14sp" />
        <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/af_dialog_background"
            android:fillViewport="true"
            android:scrollbars="none" >
            <TextView
                android:id="@+id/txt_dailog_message"
                style="@style/TextViewStyle_aboutus"
                android:lineSpacingMultiplier="1.2"
                android:text="@string/af_logo_10_dialog_content"
                android:textColor="@color/white4"
                android:textSize="14sp" />
        </ScrollView>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/btn_cancel"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@drawable/btn_cancelclick"
            android:contentDescription="@string/action_settings"
            android:paddingBottom="8dp"
            android:paddingTop="8dp"
            android:text="@string/af_cancel"
            android:textColor="@color/white"
            android:textSize="16sp" />
        <Button
            android:id="@+id/btn_ok"
            style="?android:attr/buttonBarButtonStyle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="5dp"
            android:layout_weight="1"
            android:background="@drawable/btn_able"
            android:contentDescription="@string/action_settings"
            android:paddingBottom="8dp"
            android:paddingTop="8dp"
            android:text="@string/af_confirm"
            android:textColor="@color/white"
            android:textSize="16sp" />
    </LinearLayout>
</LinearLayout>

最后是style:

1
2
3
4
5
6
7
8
9
10
<style name="Theme_Transparent" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:background">@android:color/transparent</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:backgroundDimAmount">0.6</item>
    </style>

谢谢hongyang大神~~开心挣钱每一天

本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/1613291,如需转载请自行联系原作者

Android第三十三期 - Dialog的应用相关推荐

  1. 【悟空云课堂】第三十三期:表达式永假/永真(CWE-570:Expression is Always False)

    关注公众号"中科天齐软件安全中心"(id:woocoom),一起涨知识! 该栏目为中科天齐全新规划的悟空云课堂,每周五下午18:00准时上线,旨在科普软件安全相关知识,助力企业有效 ...

  2. Android(三十二):AlertDialog 对话弹窗

    展示 源码 普通弹窗 var btn01 = FindViewById<Button>(Resource.Id.btn_01); var btn02 = FindViewById<B ...

  3. Android第三十八期 - 评价标签FlowLayout

    代码已经整理好,这里要说一下,因为手动和Json获取写法不一样. 手动直接xml设置: <LinearLayout xmlns:android="http://schemas.andr ...

  4. Android第三十一期 - 市面上所有引导页的效果

    代码已经整理好,有十几种,自己选择用吧,效果如下: 地址:http://down.51cto.com/data/1981257 引导页ViewPageAll 地址:http://down.51cto. ...

  5. android内容提供者_挖穿Android第三十九天

    为什么需要内容提供者 回顾数据库知识: [1]定义一个类继承SqliteOpenHelper [2]想要操作数据库必须获取一个SqliteDatabase对象 [3]chmod修改文件的权限 实际应用 ...

  6. 第三十三期:对于人工智能的恐惧及其5个解决方法

    实施人工智能技术的IT领导人可能会感到一些恐惧,这有着充分的理由.人工智能在拥有数十年发展和应用历史的同时却有着奇怪的定位,但对于许多人来说,人工智能仍然是一种未来主义的感觉. 实施人工智能技术的IT ...

  7. PhoneGap对比html5写android应用程序【android进化三十八】

    什么是PhoneGap,其实就是在手机中可以写html代码的插件,下面一段话来源网摘"PhoneGap是一个开放源代码的,跨平台的构建移动应用程序的框架.在PhoneGap中,完全通过HTM ...

  8. Android(三十九):Gestures 手势

    展示 源码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi ...

  9. Android第三十四期 - 极光推送

    代码已经整理好,参照官网的文档很快你会可以配置出来,如下效果:

最新文章

  1. linux查看软件包信息,Linux查看系统信息的一些命令及查看已安装软件包的命令...
  2. 鸟哥的Linux私房菜(基础篇)- 第十一章、认识与学习 BASH
  3. 【通俗解释】余弦相似度
  4. 循环自相关函数和谱相关密度(五)——实信号、复信号模型下的QPSK信号循环谱MATLAB仿真结果及代码
  5. mysql 修改表名的方法:sql语句
  6. LeedCode篇:876. 链表的中间结点
  7. 大屏实时监控-2019年CSDN博客之星年度总评选(2019-02-07 13:47)
  8. sharepoint_wf 启动窗口设计,支配给自由域用户
  9. 广商14级软件工程分数:第一回合
  10. win 10 系统激活
  11. 南自以太网103规约
  12. python生成随机姓名
  13. 360 和 qq 之争
  14. 测试人员需要具备的基本技能
  15. K-divisible Sum
  16. mysqli mysql assoc_mysqli_fetch_assoc()期望参数1为mysqli_result或如何获取MySQLi
  17. 新手学开车,起步,停车,倒库移库,练习图解,开车基本技巧
  18. linux——进程的概念与状态
  19. IOST与Gravity达成战略合作,链接Gravity网络携手开发跨链集成
  20. 华为鸿蒙系统HarmonyOS学习之十一:华为个人开发者账号注册步骤及方法

热门文章

  1. ssh 执行 SSH2_MSG_SERVICE_ACCEPT 慢问题
  2. OpenStack常见命令与问题集合
  3. zabbix agent启动不了
  4. VBA中让程序休眠 SLeep的方法
  5. 黑群硬盘休眠问题的一种解决思路(DS916+,DSM 6.1.7)
  6. python异常处理与导入模块与导入包
  7. 解决vue项目在ie浏览器缓存问题。
  8. 为什么用JS取不到cookie的值?解决方法如下!
  9. js解决浏览器打印自动分页的问题
  10. 在多行中查找和替换vim中的字符串