【问题标题】:Instantiating a widget layout on the lock screen Android在锁定屏幕 Android 上实例化小部件布局
【发布时间】:2014-09-12 00:25:22
【问题描述】:

我看过其他关于锁屏小部件的帖子。我知道 4.2 是有锁屏 API 的最新版本。

我的问题是我创建了一个 xml:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="294dip"
    android:minHeight="72dip"
    android:updatePeriodMillis="0"
    android:initialLayout="@layout/keyguard"
    android:widgetCategory="keyguard">
</appwidget-provider>

还有一个布局:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyguard"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black" >

    <RelativeLayout
        android:id="@+id/appwidget"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/controls"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center">

            <ImageButton
                android:id="@+id/control_play_pause"
                android:layout_width="100dip"
                android:layout_height="wrap_content"
                android:background="@null"
                android:src="@drawable/ic_media_play_dim"
                android:paddingTop="1dip"
                android:paddingBottom="1dip"
                android:scaleType="centerInside" />

            <ImageView
                android:background="@android:color/white"
                android:layout_width="1dip"
                android:layout_height="20dip" />

            <ImageButton
                android:id="@+id/control_stop"
                android:layout_width="100dip"
                android:layout_height="wrap_content"
                android:background="@null"
                android:src="@drawable/ic_media_stop_dim"
                android:paddingTop="1dip"
                android:paddingBottom="1dip"
                android:scaleType="centerInside" />

        </LinearLayout>

    </RelativeLayout>

</FrameLayout>

我对提供程序并不完全清楚(但我已经制作了一个并将其添加到 AndroidManifest.xml),因此我们将不胜感激。现在,我只想在锁定屏幕上显示该布局(只是一个简单的媒体播放器控件)。

谢谢!

【问题讨论】:

  • 媒体播放器控制锁屏小部件?代替或补充RemoteControlClient 已经在锁定屏幕上立即创建了用于媒体播放控制的小部件?
  • 谢谢。但是我要这样做的方式需要一个自定义版本。我不会前进或后退,播放会切换到暂停和停止按钮。
  • 您可以准确控制 RemoteControlClient 上显示的按钮,这样就不会破坏交易。请注意,如果您想在 Android Wear 设备上显示音乐控件,并且锁定屏幕小部件在较新的三星手机上不可用(例如 S5 - 它们被三星特别禁用)并且在当前的手机上根本不可用,则需要 RemoteControlClient Android L 开发者预览版。
  • 我最深切的歉意,ianhanniballake。我太仓促了。我下载了 RandomMusicPlayer 演示,发现按钮是可控的。我将对此进行深入研究,但我认为您的回答足以满足我的需求。

标签: android widget locking screen lockscreen


【解决方案1】:

如果您只需要自定义媒体控制按钮,您可以使用RemoteControlClient 自动将音乐控制发布到锁定屏幕。可以使用RemoteControlClient.setTransportControlFlags 方法自定义控件,传入与您要显示的按钮相关联的标志。

【讨论】:

  • 好的,我弄乱了 .setTransportControlFlags 并且似乎无法显示真正的停止按钮(方形块) 我尝试了各种标志但无法获得实际的停止按钮。 RemoteControlClient.FLAG_KEY_MEDIA_STOP 显示暂停(双竖线)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2022-07-22
  • 1970-01-01
相关资源
最近更新 更多