I want to show a popup menu from a home screen widget like the one in the picture below, but there is a View anchor
argument in the PopupMenu constructor method.
But I don't have access to the view in AppWidgetProvider
class and only the RemoteViews are available.
So, How can I implement a popup menu in my widget?
Any help would be appreciated. Thanks.
You can't use the android.support.v7.widget.PopupMenu
directly with RemoteViews
. But you are able to copy that behaviour:
PendingIntent
with a defined intent action and set it with setOnClickPendingIntent
for the anchor view Intent
in onReceive
of your AppWidgetProvider
by the intent action intent.getSourceBounds()
to get the screen position of the clicked anchor view Activity
and transmit the screen position to that Activity
PopupMenu
at the transmitted screen position in the transparent Activity
finish()
the transparent Activity
if the user clicks not on an item of the PopupMenu
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.