android - 在 Android Wear 上设置背景

标签 android wear-os

我正在尝试为 Android Wear 上的通知设置背景,但出现错误

setBackground in android.support.v4.app.NotificationCompat.WearableExtender cannot be applied to (int)

我已经尝试了一段时间,但我被难住了。

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Code Received")
            .setContentText("Your Orange Wednesday code is " + orangeCode)
            .extend(new NotificationCompat.WearableExtender().setBackground(R.drawable.orangebg));

如果有人能够指出我正确的方向,那将不胜感激。 谢谢

最佳答案

如文档中所示,该方法需要位图作为输入。

https://developer.android.com/reference/android/support/v4/app/NotificationCompat.WearableExtender.html#setBackground(android.graphics.Bitmap)

public NotificationCompat.WearableExtender setBackground (Bitmap background)

Set a background image to be displayed behind the notification content. Contrary to the NotificationCompat.BigPictureStyle, this background will work with any notification style.

Parameters

background - the background bitmap

R.drawable.XXX 是框架用于查找您的实物 Assets 的整数标识符。使用 BitmapFactory.decodeResource(context.getResources(), R.drawable.XXX) 从您的 Assets 中检索位图并稍后应用。

关于android - 在 Android Wear 上设置背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25188364/

相关文章:

Android Wear类型检测——圆形或方形

android - 选择自定义表盘时黑屏

java - Android 将 TextViews 添加到 fragment 中

android - 有什么办法可以根据动态值来限制 ListView 中复选框的选择吗?

android - 如何确保已调用 onDataChanged?怎么办?

android - Google License Verification Library 是否可以在 Android Wear 设备上运行?

android - Android Wear 上的加速度计会耗尽电池电量吗? (安卓 watch )

java - UnsatisfiedLinkError: 无法从加载程序加载 X

android - 使用来自多个模块 dagger 2.11 android 的依赖项

java - 如何将项目从 Edittext 添加到 ListView ?