How to activate option menu when search box is displayed? (SearchManager) - android

I am trying to build a quick search box. it is basically a widget. Upon clicking, it pops up the quick search box and launch the browser with query string. No activity except searchactivity.
And also added codes for 'recent query suggestion' But having a problem to have menu for 'clear history' Here is what I wanted to implement. When quick search box is displayed, by pressing menu button, I want option menu to be popped up, keypad to be disappeared, quick search box to be stayed.
the implementation of google sample code - Searchable dictionary is not what I want to implement. It starts an activity with instruction message and when a user presses the search button or menu button, it pops up the quick search box. Mine is when it runs from a widget, the quick search box is popped up right away just like the google search widget.
How can I override onCreateOptionMenu on searchmanager? Or is there any way to activate option menu when the searchmanager is activated?
Please take a look at the images below. the second image is what I want to implement upon clicking menu button.

What you need to do is make the search button launch the default search activity when it is pressed. And make it sorta match the existing search dialog style. You can notice this is how the official Twitter client works. You can use apktool (google it) to take a look at the official Twitter clients resource files to get a better idea of how this can be accomplished.

Related

How do I automatically remove focus from searchview in android app after clicking on it

I m making book finder app.
step1: i clicked on search button and activity is waiting for my book title
step2: i input some book title
step3: the focus still stays on this search button, i have to click on screen to make it go away.
is there way to automatically loose focus on last widget i clicked on?
You probably just want to call requestFocus() on your book list whenever a search completes (however, if there are no results, you may want to re-open your search box, or do so after a delay). There is also a OnFocusChangedListener which might be of help if requesting focus on your list after serving up results does't work for some reason.

Android : Provide alternative context menu to user

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.

Android - always enable search box

I am making a dictionary program and the problem I have faced so far is getting a "search box" to be enabled at all times while the program is running. In my case, when you run the program, it displays a black screen with nothing there. The user has to press the search button to bring up the search box. How can I make it so that the user won't have to press that button?
You have a couple options here.
You can invoke the search dialog in your main Activity's onCreate() by calling: onSearchRequested(). However, if the user hits the back button at any point in the search dialog, it will dismiss the search dialog and the user will have to hit the search button to bring it back up.
You could create an AutoCompleteTextView that will handle the searching & displaying of the dictionary items. This will be a little more involved, but will guarantee that the "search box" will always be displayed (and the user won't be able to dismiss it).

How to blur background of search dialog?

I’ve created a search activity in my app, in the standard Android way, without custom suggestions. When a user starts typing text or presses the search button, they get a search dialog with search box, something like figure 1 from here:
http://developer.android.com/guide/topics/search/search-dialog.html
You’ll notice in the background is the previous activity, the words “abide”, etc.
My problem is that the previous activity is shown clear as day behind the search dialog, and its confusing for users, because users think all that is still active, and they try to press on it, but it just cancels the search dialog. And it distracts the user from the search task (are those search results, they may wonder?).
Question: how to blur (make out of focus) or darken the previous activity?
I actually see this in some app’s search screens.
I found a simple way to blur the background of the search dialog:
Basically it's just adding a (half) transparent view over the ListView (or what is under the dialog) and hide it by default. If the search dialog appears (calling onSearchRequested()) it is set to visible, if it disappears it's set back to gone (invisible).
Check out the details at my blog: http://mavistechchannel.wordpress.com/2011/08/13/blur-background-android-search-dialog/
Assuming you got dialog from a Dialog.Builder, use the following:
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

Opening ContextMenu by Clicking a Button in Android

How to open the ContextMenu in Android by Clicking a Button?
A context menu is conceptually similar to the menu displayed when the user performs a "right-click" on a PC. You should use a context menu to provide the user access to actions that pertain to a specific item in the user interface.
On Android, a context menu is displayed when the user performs a "long press" (press and hold) on an item.
Alternatively, if you need a button, you can implement the menu for the view and change the content dynamically.
Your question is bad and you should feel bad, given how readily available (if cryptic) the method behind this process is. This small tutorial helped me greatly.
http://www.mikeplate.com/2010/01/21/show-a-context-menu-for-long-clicks-in-an-android-listview/

Categories

Resources