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
    评论
Android 蓝牙弹出配对指的是在Android设备中,当我们打开蓝牙连接功能时,会弹出一个配对,用于配对并连接其他蓝牙设备。 在Android中,我们可以通过以下步骤实现蓝牙弹出配对: 1. 打开蓝牙:在应用中的相应位置,通过调用蓝牙适配器(BluetoothAdapter)的enable()方法,可以打开设备的蓝牙功能。 2. 搜索设备:调用蓝牙适配器的startDiscovery()方法,会开始搜索附近的蓝牙设备。搜索过程可以通过广播接收器(BroadcastReceiver)监听蓝牙设备的变化。 3. 弹出配对:当检测到附近有新的蓝牙设备时,Android系统会自动在设备上弹出配对,显示可用的蓝牙设备列表。 4. 选择要配对的设备:在配对中,用户可以选择要配对的设备。通常会显示蓝牙设备的名称和MAC地址等信息。 5. 开始配对:用户选择要配对的设备后,点击确认按钮,系统会发起配对请求。在这个过程中,系统会尝试与被选择的设备建立安全连接。 6. 配对结果:配对过程完成后,系统会返回配对结果。如果配对成功,我们可以获取到连接到的蓝牙设备对象,可以通过该对象与蓝牙设备进行数据传输。 需要注意的是,不同的Android版本或设备可能会有一些差异,因此在开发过程中需要根据不同情况进行适配。同时,还需要处理一些配对失败或取消配对的情况,以提高用户体验。 总之,Android蓝牙弹出配对是通过系统级的弹出选择和处理蓝牙设备的配对过程,让用户在使用蓝牙功能时能够方便地与其他设备进行连接和交互。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值