I have created a widget in my application , now when a widget is clicked I want to show few options in a context menu and allow the user to choose one of them.
My widget contains icon and text , so when a user click over an icon of widget i want to show the context menu.
is there a way to do it ? i am using android 2.3.X and android support compatibility package too.
here is what i want
The widget that i have created is derived from AppWidgetProvider class.
I think there is no way to open a context menu when we click on widget.
But alternatively we can open an activity instead and make it transparent then open a dialog box which contains ListView in that way we can mimic the look of context menu.
That is how i eventually did in my application.
Related
I noticed that when I "longclick" on a specific message in apps like FB, Viber, & Whatsapp, it will open up either a floating context menu or default action bar context menu.
What I would like to know is if it's possible to listen to a highlighted parts of text event in that particular textview and open a totally custom menu like a tooltip with different actions, not relying on context menu action mode. So far, I was only able to implement long click listening to an entire textview wherein that custom tooltip will appear.
Thanks for your advice.
On android, whenever the user long-clicks on a text field, they get a context menu with options like 'copy' , 'paste', 'select all' etc. Now, I'm aware I cannot add my own items to this menu, system-wide - android won't and shouldn't let me. But I can write my own context menu from scratch, and whenever the user long-clicks on a text view, they will be given two options - 1. System context menu 2. My own menu.
I know this can be done, but I don't know what API calls to use, to achieve this.
Existing applications that do something similar:
Swype keyboard: This keyboard application overrides the system keyboard. So when user clicks on a text view to type something, they're given two options, namely - 1. Default system keyboard, or 2. Swype keyboard user installed. User also gets the option to make one of them the default.
Similarly, Go Launcher Ex: System wide whenever we press the 'Home' button, we get two options - to display the regular Home screen, or display the Go Launcher Home screen.
Any suggestions, or reference material are highly appreciated.
Thanks!
Both of your examples are accomplished using Intent filters. However, the EditText's context menu is not shown using an Intent, and therefore cannot be overridden in this way.
You can override the menu in your app using onContextMenu and related API's but there is no way to do so for other apps.
I have found examples here: Android - Intent that open widget context menu and here: http://coderender.blogspot.com/.
The first one launches the widget picker, but goes it goes away when you select anything. The second one lets you pick a widget, but it shows it in the application view. Is there a way to call the widget selection from a button in an app but still have the main screen on the phone be the AppWidgetHost?
It may be me misinterpreting things, but it looks to me like the AppWidgetHost has to be the application where you are calling the widget selection menu.
Is there a way to call the widget selection from a button in an app but still have the main screen on the phone be the AppWidgetHost?
Only if you are the home screen.
It may be me misinterpreting things, but it looks to me like the AppWidgetHost has to be the application where you are calling the widget selection menu.
More importantly, it is the AppWidgetHost that must do the work to make use of the selection.
I have an Activity which provides UI for editing entity properties such as name, description an so on. This entity can also have an icon but (this is the main problem) can have no icon. I have created an icon picker activity which provides UI for icon selection. But I can not think of a simple and pretty way to provide access to this picker from parent activity. It could be a simple image button if the task was just to select an icon but I have also to make it possible to remove already set icon. Having two buttons with 'choose' and 'remove' seems ugly. Any smart ideas?
UPDATE
I've ended with ImageButton showing selected icon or special 'No' icon if object has no icon. On button click I show PopupMenu on 3.0+ and ContextMenu on older versions. Menu contains 'Change' and 'Remove' items.
You could have a border that surrounds an empty space or the image if there is one already.
If the image exists, clicking on it brings up a dialog where you can choose to change it or remove it.
If it doesn't exist, clicking on it brings up a dialog where you can add it.
how about a gridview within a custom dialog fired from your parent activity??
change the icon onItemSelected() of the gridview??
I've read through all of the android documentation that I can find but I'm still not clear on whether a button can be added to an application for an android device somewhere outside of an options/context menu. It seems like all of the menu buttons are only accessible either from a tab bar at the bottom or the menu button on the device. Is this correct?
I'm not sure I understand what you mean, but you can use a Button widget in an activity anywhere you want, just like any other widget type. See:
http://developer.android.com/reference/android/widget/Button.html