Android自定义view之弹出式dialog

闲谈:

发觉好久没有写长博客了,一是自己处于忙碌状态,没有时间写,其实最主要的还是归咎于自己太懒了。天下武功,唯懒不破。那就做一只早起的鸟儿吧。


前言:

在初学android的时候,就一直觉得系统的dialog写的简直是丑爆了,看到很多app都用了自己自定义的,感觉效果超棒,心想,哪天自己也有这个水平就好了,于是乎,下定决心,好好学习android。吐舌头废话太多了,赶紧今天的教程吧。


正文:

今天我们要实现的效果图是这样的:


这样的dialog比原生的好看多了,至少我是这样认为的害羞。其实做出这样一个效果还是不难的,代码来说,也不是很多。

项目结构图:


要学习这篇博客,首先要会一些常见的自定义style,和常见的android基础,我们这边没有用到自定义属性。

先来看看我们的主要布局吧。主要布局也就只有三个button,我就不详细说明怎么布局了,直接把代码贴上来了。

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_gray_normal"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/selector_btn_blue"
        android:padding="@dimen/dip10"
        android:text="btn1" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dip10"
        android:background="@drawable/selector_btn_blue"
        android:padding="@dimen/dip10"
        android:text="btn2" />

    <Button
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dip10"
        android:background="@drawable/selector_btn_blue"
        android:padding="@dimen/dip10"
        android:text="btn3" />

</LinearLayout>
当然这边有些color,dimen,也贴出来。

colors.xml:

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

    <color name="color_blue_l
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值