Android 四种弹出框

记录一下,方便记忆

在这里插入图片描述

一.Dialog

二.PopupWindow

请看另一篇:https://mp.csdn.net/postedit/82692365

三.Activity

四.BottomSheetDialog

BottomSheetDialog继承AppCompatDialog,AppCompatDialog继承Dialog。看到这里,应该知道BottomSheetDialog的一些特征。

BottomSheetDialog使用很方便,自定义View除外:

BottomSheetDialog bsd = new BottomSheetDialog( this );
//将要添加的布局文件
View rootView = View.inflate( this, R.layout.bottom_sheet_activity, null );
TextView title = rootView.findViewById( R.id.title );
title.setText( item.getName() );
TextView content = rootView.findViewById( R.id.content );
content.setText( item.getDemo() );
ImageView cancel = rootView.findViewById( R.id.cancel );
//取消点击事件
cancel.setOnClickListener( v1 -> bsd.dismiss() );
//将布局文件添加到BottomSheetDialog中
bsd.setContentView( rootView );
//显示
bsd.show();

bottom_sheet_activity.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="wrap_content"
    android:background="@color/white"
    android:orientation="vertical"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/size_dp_43"
        android:background="@drawable/button_gray_white"
        android:orientation="vertical">


        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:paddingLeft="@dimen/size_dp_15"
            android:paddingRight="@dimen/size_dp_15"
            android:textColor="@color/font_color"
            android:textSize="@dimen/text_size_14"/>

        <ImageView
            android:id="@+id/cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:contentDescription="@null"
            android:paddingLeft="@dimen/size_dp_10"
            android:paddingRight="@dimen/size_dp_10"
            android:src="@mipmap/arrow"/>

    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/size_dp_0.5"
        android:background="@color/datum_background"
        />

    <TextView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/size_dp_10"
        />


    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/size_dp_10"
        />

</LinearLayout>

其它方式持续更新…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值