Reputation: 556
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.
Upvotes: 1
Views: 766
Reputation: 4848
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 viewIntent
in onReceive
of your AppWidgetProvider
by the intent actionintent.getSourceBounds()
to get the screen position of the clicked anchor viewActivity
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
Upvotes: 1