Is there a way to add a custom case to the existing context menu in Android? We all have a context menu that is called on the active EditText view, the one with "Input Type" and other. What I need is to add another case to this menu, say "Options". I honestly searched for info on Android Developers, but no luck over there. They only write about creating your own menu from scratch. I don't need to change it systemwide as this guy does. My only concern is to change it in one activity of my app, one instance of EditTextto be precise.
See https://stackoverflow.com/a/7383161/1351347
It is NOT possible to override the system-wide contextMenu. You could (as you already know) push another contextMenu on a longClick on this single EditText.
Related
I'm trying to set up a menu that appears when the user starts the app for the 1st time, so they can set it up by choosing from 1 of 6 items. It needs to start automatically dependent on a boolean value taken from sharedPreferences.
I have been trying to create a context menu, but its not working and I'm not sure if its the right way to go about it.
Has anyone done this and is context menu the right way to go? If not, please could you point me in the right direction.
Many thanks
You shouldn't be using a ContextMenu for this kind of design. You should be using a Custom Dialog for the configuring of your app. Using perhaps a ViewSlider to allow multiple configuration screens or just one View with all the configuration options in a ScrollView.
When there's more than 6 items in the Android Option Menu, a "More" will be in place. My question is currently I see two different behaviors upon clicking, from different apps. One will show a menu like this, another will show a context menu like this.
Which is one is the proper Android way?
Thanks
I don't see how those two are related. Your first link shows the options menu with "more", which is what you were talking about in your first sentence. The second link shows the context menu after a long press on a list item - that's a completely different item. They both have their uses.
The menu is used for options that are global to the current activity. The context menu is intended for options that relate to the specific item you picked.
If you see an app that uses a context menu for "more", then it's not using the normal Android menu system. I've even seen Google apps use that (Maps, I believe), and I don't know why you would do that.
The first is the "proper" way as in the default behaviour you get. I don't think the difference is meaningful, but to achieve the second the coder must have mucked around, and I don't think it's worth it..
When I enter some text and press and hold on it then context menu is presented with items like cut,copy,select text and so on.
Is there any way to add my own custom item to this context menu ? I do not how this things works but I guess that should be possible to register something in the manifest just like registering activities and broadcasts . . .
Thanks,
Any ideas are wellcomed
Is there any way to add my own custom item to this context menu ?
Only for widgets in your own activities, not for the system as a whole.
Also, EditText is problematic even for your own activities, as some device manufacturers are bypassing the normal context menu system, so you can't add to them.
That being said, for your own activities, just follow the instructions to create a context menu for the widgets of interest.
Have you tried putting an onLongClickListener on your EditText? This won't let you add to the current list, but you can make your own dialog show up and then add all the options above, or some of them, or none of them and your own.
I'm not sure if exactly what you're asking for is possible, and if it is my way is a little bit more work, but you'll have full control.
Is there a standard way to add a footer to a context menu, in which I can add a checkbox to make the selected option the default one?
Similar to the context menu that comes up when choosing the default home screen for example.
From the Api docs for ContextMenu I see that you can set a header view, but not a footer view. Also the setCheckable / setGroupCheckable methods don't seem to help much here.
Does this need to be done via a custom (alert) dialog? I would be wondering if nobody has yet developed such a component yet in case it's not possible through the standard SDK api. Any standalone open source component out there (beside the Android source itself)?
The best I've come up with is using an AlertDialog
alert.getListView().addFooterView(...); and overriding it's onItemSelected method.
I'm writing an application with EditText driven widget. and I'd like to create my own copy & paste menu. To replace android default menu on EditText, what should I do?
Just overriding long click? or is there another way to implement?
Thanks in advance.
EditText should already have a context menu enabled. If it were not, then you would have to enable it by calling registerForContextMenu. Once you have the context menu enabled, you have to add items to it. This is done in onCreateContextMenu by using one of the Menu.add methods.
The hard part is writing the code for onContextItemSelected after the user has selected an option. Saving text to the clipboard is simply a matter of calling ((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText("myText");. However, first we need to find what text to copy. I haven't figured this last part out yet, but I am hopeful that I will soon.
Related Questions
Show context menu when link is long pressed in TextView
It is considered to be somewhat of a standard exercise to implement copy/paste the hard way by overwriting the menu system, creating the menu items yourself, and your own internal buffer.
However, that is not how it should be done if a better way is available on the platform. Reimplementing platform functions is good for learning but bad for maintenance.
Community Wiki as this is not a real answer and I should not get rep for this.