【Android-Activity】popupwindow的使用总结

本文介绍了在Android开发中如何使用PopupWindow,包括设置点击事件触发popupwindow、定制popupWindow布局、设置属性以及实现popupWindow显示在按钮下方等功能。通过实例步骤,展示了popupwindow的常见应用场景。
摘要由CSDN通过智能技术生成

popupwindow是我们在开发中常用的组件,本文将主要介绍实现popupwindow的方法:
实现效果:
在这里插入图片描述

实现步骤:

1、设置button,对button设置一个点击事件,即点击时跳出popupwindow
    <Button
        android:id="@+id/btn_button"
        android:textAllCaps="false"
        android:layout_centerInParent="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="popup" />
        Button btn=findViewById(R.id.btn_button);
        btn.setOnClickListener(new View.OnClickListener() {
   
            @Override
            public void onClick(View v) {
   
                
            }
        });
2、设置popupWindow的布局

此处可以用recyclerView或者listView来实现,此处写法只是为了展示效果
此处的View的首字母一定要大写!

<?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">

    <TextView
        android:id="@+id/tv_good"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="20dp"
        android:paddingBottom="20dp"
        android:text="好" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值