惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
WordPress大学
WordPress大学
雷峰网
雷峰网
小众软件
小众软件
D
DataBreaches.Net
V
Visual Studio Blog
博客园 - Franky
IT之家
IT之家
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
博客园 - 聂微东
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
云风的 BLOG
云风的 BLOG

博客园 - MSTK

PCB检测算法YOLO-EMAC(2) PCB检测算法YOLO-EMAC(1) Android Studio提高Build速度 Android创建LiteOrmManager类(4) DecoView的使用 Android创建LiteOrmManager类(3) Android创建LiteOrmManager类(2) Android创建LiteOrmManager类(1) Unable to add window -- token null is not valid; is your activity running? Android Studio集成通义灵码 MonoDETR(2) MonoDETR(1) The color "XXX" in values has no declaration in the base values folder; this can lead to crashes when the resource is queried in a configuration that does not match this qualifier LiteORM的使用(2) LiteORM的使用(1) 使用AlarmManager实现APP保活(2) 使用AlarmManager实现APP保活(1) CEC2017的30个函数 使用双进程实现Android APP保活 Process finished with exit code 137 (interrupted by signal 9: SIGKILL) GIT RE-BASIN: MERGING MODELS MODULO PERMUTATION SYMMETRIES (1) MMpretrain使用Tiny ImageNet数据集 Ubuntu使用dd命令实现硬盘级复制 PyCharm debug collecting data...
Android使用Snackbar
MSTK · 2025-12-29 · via 博客园 - MSTK

首先,在build.gradle中添加:

implementation 'com.google.android.material:material:1.6.0'

使用的代码:

    public static void showToast(View view, Context context, String message, int duration) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            // API 14及以上,可以使用Snackbar
            Snackbar snackbar = Snackbar.make(view, message, duration);
            snackbar.setBackgroundTint(context.getColor(R.color.blue));
            snackbar.show();
        } else {
            // 对于极其古老的设备(API<14),回退到Toast
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        }
    }