我在我的画中画模式中添加了一个可绘制的黑色检查图标。它是黑色的,在 pip 窗口中它像其他默认 pip 图标(设置图标、十字图标)一样以白色显示。
我也尝试过传递一个红色图标,它也变成了白色。
是否可以像实际出现的那样在 PIP 窗口上显示图标?
以下是我添加的用于向 PIP 窗口添加图标的代码
internal fun updatePictureInPictureActions(
@DrawableRes iconId: Int, title: String, controlType: Int, requestCode: Int) {
val actions = ArrayList<RemoteAction>()
// This is the PendingIntent that is invoked when a user clicks on the action item.
// You need to use distinct request codes for play and pause, or the PendingIntent won't
// be properly updated.
val intent = PendingIntent.getBroadcast(
this,
requestCode,
Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val icon = Icon.createWithResource(this, iconId)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
actions.add(RemoteAction(icon, title, title, intent))
mPictureInPictureParamsBuilder.setActions(actions)
setPictureInPictureParams(mPictureInPictureParamsBuilder.build())
var result = enterPictureInPictureMode(mPictureInPictureParamsBuilder.build())
Log.i(TAG, " result of enterPictureInPictureMode - " + result)
}
} else {
TODO("VERSION.SDK_INT < M")
}
}
我添加了我的 PIP 窗口的屏幕截图以供参考。