Android0828<十>(自定义的AlertDialog,Popup Window,Notification)

本文详细介绍了如何在Android中自定义Dialog,包括使用Shape设置颜色、边框和圆角,以及如何在styles中配置主题。此外,还探讨了PickerDialog用于弹出时间日期的选择,以及PopupWindow的使用方法,包括设置内容、宽度和高度。最后,讨论了Notification的创建和管理,作为状态栏提醒的重要机制。
摘要由CSDN通过智能技术生成
自定义Dialog 和Shape

自定义的Dialog需要先建立一个drawable放Shape来设置dialog的颜色、边框、和圆角,以下是几个属性

corners圆角率

<corners 
android:bottomLeftRadius="10dp"左下角为半径为10dp的圆角
android:topLeftRadius="10dp"左上角为半径为10dp的圆角
android:topRightRadius="10dp"右上角为半径为10dp的圆角
android:bottomRightRadius="10dp"右下角为半径为10dp的圆角
android:radius="10dp"     四角都为半径为10dp的圆角
    />

solid Dialog背景颜色

<solid android:color="#BFEFFF"/>

stroke android:color边框颜色 android:width边框大小

 <stroke android:color="#9AFF9A" android:width="1dp"/>

若要设置dialog背景也为圆角,需要在styles中设置dialog的theme,注意的是在dialog中添加theme

<style parent="@android:Theme.Dialog" name="NoDialogTitle">

        <item name="android:windowFrame">@null</item>

        <item name="android:windowNoTitle">true</item>

        <item name="android:windowBackground">@android:color/transparent</item>

        <item name="android:windowIsFloating">true</item>

        <item name="android:windowContentOverlay">@null</item>
    </style>

自定义的activity_dialog_define.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@mipmap/image_girlsmall"
    >

<TextView
    android:id="@+id/text_dialog_define_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="这是自定义标题"
    android:textColor="#50ff0000"
    android:gravity="center"
    android:padding="10dp"
    android:background="@drawable/bac_dialog_define"/>
    <TextView
        android:id="@+id/text_dialog_define_massage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="这是自定义的内容"
        android:gravity="center"
        android:padding="20dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:id="@+id/btn_dialog_cannel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="cannel"
            android:background="@drawable/bac_dialog_btn_anncel"/>
        <Button
            android:id="@+id/btn_dialog_sure"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="OK"
            android:background="@drawable/bac_dialog_sure"/>
    </LinearLayout>
</LinearLayout>

修改的主题styles

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>
    <style parent="@android:Theme.Dialog" name="NoDialogTitle">

        <item name="android:windowFrame">@null</item>

        <item name="android:windowNoTitle">true</item>

        <item name="android:windowBackground">@android:color/transparent</item>

        <item name="android:windowIsFloating">true</item>

        <item name="android:windowContentOverlay">@null</item>
    </style>

</resources>

设置背景圆角以及按钮形状的drawable
bac_dialog_defien.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:topRightRadius="10dp" android:topLeftRadius="10dp"/>
    <stroke android:color="#FFFACD" android:width="1dp"/>
    <solid android:color="#FFA54F" />
</shape>

bac_dialog_btn_annel.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:bottomLeftRadius="10dp"
   />
    <solid android:color="#BFEFFF"/>
    <stroke android:color="#9AFF9A" android:width="1dp"/>
&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值