实现简单的PopupWindow功能

PopupWindow 是在 Android 开发中常用的悬浮窗口控件,用于在当前视图上弹出一个窗口,通常用于显示临时信息、提示或菜单选项。使用 PopupWindow 的简单流程如下:

1. 创建 PopupWindow 实例

使用 PopupWindow(View contentView, int width, int height) 创建对象,并指定要展示的内容视图、宽度和高度。

2. 设置 PopupWindow 的属性

- setFocusable(boolean focusable): 设置焦点是否可以获取。

- setOutsideTouchable(boolean touchable): 设置点击外部是否可关闭。

3. 显示 PopupWindow

使用 showAtLocation(View parent, int gravity, int x, int y) 指定显示位置或 showAsDropDown(View anchor) 显示在指定视图下方。

4. 关闭 PopupWindow

通过 dismiss() 方法关闭 PopupWindow。

以上是 PopupWindow 的基本使用方法,具体实现需根据项目需求自定义。

folder
PopupWindow 预估大小:1393个文件
file
gradlew.bat 2KB
file
localJarClasspathSnapshot.bin 20KB
file
localClassSetAnalysis.bin 25KB
file
fileHashes.bin 139KB
file
taskArtifacts.bin 80KB
file
fileSnapshots.bin 1.93MB
file
outputFileStates.bin 20KB
file
app-debug-unaligned.apk 1.29MB
file
app-debug.apk 1.29MB
file
resources-debug.ap_ 371KB
file
resources-debug-androidTest.ap_ 755B
file
ResultReceiver.aidl 675B
file
RatingCompat.aidl 673B
file
MediaSessionCompat.aidl 787B
file
ParcelableVolumeInfo.aidl 689B
file
PlaybackStateCompat.aidl 688B
file
MediaMetadataCompat.aidl 680B
file
R$styleable.class 24KB
file
MainActivity.class 37KB
file
MainActivity.class 37KB
zip 文件大小:26.98MB