【发布时间】: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