Android 使用液态玻璃(LiquidGlass)效果,真实的折射和色散效果


特性

  • 真实的的液体玻璃效果 - 基于物理的折射色散效果
  • 高度可定制 - 支持调整圆角、折射参数、色散、色调等

要求

  • Android API 33 及以上(Android 13),以获得完整的玻璃效果

Demo 示例

下载 Demo

GitHub

GitHub仓库


快速集成

添加仓库

在项目根目录的settings.gradle添加仓库:

gradle 复制代码
1dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
       mavenCentral()
       maven { url 'https://jitpack.io' }
  }
}

添加依赖

在模块的build.gradle添加依赖项:

gradle 复制代码
dependencies {
   implementation 'com.github.QmDeve:AndroidLiquidGlassView:v0.0.1-alpha02'
}

如何使用

XML布局

xml 复制代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- 内容容器 -->
    <FrameLayout
        android:id="@+id/content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/images"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/image" />

        </RelativeLayout>
    </FrameLayout>

    <!-- 液态玻璃视图 -->
    <com.qmdeve.liquidglass.widget.LiquidGlassView
        android:id="@+id/liquidGlassView"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true" />
</RelativeLayout>

绑定采样源

java 复制代码
ViewGroup content = findViewById(R.id.content_container);
LiquidGlassView liquidGlassView = findViewById(R.id.liquidGlassView);

// 绑定采样源
liquidGlassView.bind(content);

API Reference

方法 描述 默认值
bind(ViewGroup source) 绑定采样源 -
setCornerRadius(float px) 设置圆角半径 (px) (0dp-99dp) 40dp
setRefractionHeight(float px) 设置折射高度 (px) (12dp-50dp) 20dp
setRefractionOffset(float px) 设置折射偏移 (px) (20dp-120dp) 70dp
setTintColorRed(float red) 设置色调(R) (0f-1f) 1.0f
setTintColorGreen(float green) 设置色调(G) (0f-1f) 1.0f
setTintColorBlue(float blue) 设置色调(G) (0f-1f) 1.0f
setTintAlpha(float alpha) 设置色调透明度 (0f-1f) 0.0f
setDispersion(float dispersion) 设置色散效果 (0f-1f) 0.5f
setBlurRadius(float radius) 设置模糊半径 (0dp-50dp) 0f
setDraggable(boolean enable) 开启和关闭拖动 true

效果说明

Android 13+ 设备上该库可以呈现完整的液态玻璃效果包括:

  • 真实且可调节的折射效果
  • 真实且可调节的色散效果
  • 可调节的模糊效果
  • 可调节的色调

Android 13 以下的设备上,该视图将保持透明背景,并且不会渲染任何效果


注意事项

1.采样源 确保绑定的采样源视图包含有效内容 2.兼容性 完整功能仅支持 Android 13+


我的其他开源库

相关推荐
花椒技术8 小时前
AI 代码评审落地实践:GitLab 接入、项目规则与反馈闭环
后端·github·agent
朱涛的自习室8 小时前
逃离“古法测试”:AI 测试的“三大定律”
android·前端·人工智能
QING6188 小时前
Android面试 —— 八股文(一)
android·面试·android jetpack
袋子(PJ)9 小时前
2026最新GitHub发布项目全过程
git·github
带娃的IT创业者9 小时前
围墙花园的隐形锁:当 reCAPTCHA 拒绝了“去谷歌化”的 Android 用户
android·隐私安全·人机验证·recaptcha·去谷歌化·grapheneos
拓研C9 小时前
EM-Core-Agent:AI Agent 具身认知核心系统——架构白皮书 V1.0
人工智能·架构·车载系统·机器人·github
awu的Android笔记9 小时前
Android 用户态实现 TCP 代理:从 SYN 到 FIN 的完整生命周期
android·tcp/ip
Geek_Vison9 小时前
技术实践:保险健康APP引入第三方小程序实战,如何构建一个安全可控的沙箱环境~
android·安全·小程序·uni-app·mpaas
2501_9159184110 小时前
Python如何抓取HTTPS请求包的完整教程与代码示例
android·ios·小程序·https·uni-app·iphone·webview
. . . . .10 小时前
android开发
android