how to keep an options menu always on the screen - android

I need the options menu to be displayed on screen always.. I've written the code to open options menu on the startup of an activity..
#Override
public void onAttachedToWindow() {
openOptionsMenu();
};
But on clicking on another item on the screen, the menu goes down.. I want the menu to be on screen always.. Is there any way to do that?

Please try the following code:
#Override
public void onOptionsMenuClosed(Menu menu) {
openOptionsMenu();
}

Related

How to hide ActionPopupWindow of Text Selection Handler of EditText

Actually I want to hide ActionPopupWindow (popup having SELECT ALL, CLIPBOARD options) when user click on + icon(refer to the attached image).
ActionPopupWindow appears when user click on the Text Selection Handler(bubble) (which appears when user tap on the text in the EditText).
I have tried to use setTextIsSelectable() method of EditText but it is not working consistently.
Any help or guidance will be well appreciated.
UPDATE: To hide the Popup already opened and showing on the screen, you need to clear focus of the current EditText or focus on other view when you clicked the plus button. See the
example below:
iconPlus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
yourEditText.clearFocus();
}
});
If you want the popup never shows up at the first place, there are many ways to do it.
The simplest way is disabling long click and selection feature:
yourEditText.setLongClickable(false);
yourEditText.setTextIsSelectable(false);
Second one is overriding action callback actions on your edittext:
yourEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
You can use them separately or together according to your case.
Also you can check other options from here

How to tell Listview Selection Mode transitions

Is there a way to know if a user exitted multiple selection mode either by pressing back or unselecting all items?
You can use the following method to register a MultiChoiceModeListener.
setMultiChoiceModeListener (AbsListView.MultiChoiceModeListener listener)
This can tell you when the user leaves the multichoice mode.
Not sure about unselecting all items. How does user perform this task?
The solution was to implement :
#Override
public void onDestroyActionMode(ActionMode mode) {
...
}
and
#Override
public void onCreateActionMode(ActionMode mode, Menu menu) {
...
}
To detect exiting and entering the multiple selection mode.

Hide CAB on EditText long press showing the Selection Markers

First of all, I have searched and tried numerous solutions posted here in StackOverflow but none of them solves my query, so this isn't a duplicate question.
I want to display a custom menu like this, when an EditText is long pressed,
As you can see that on Long Press on the EditText, this floating menu appears instead of the stock CAB, and the selection markers are also intact.
I want to achieve this kind of menu for my app. I have tried using this code, while it disabled the CAB but also prevents the selection markers from appearing,
editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
});
Also, if I try customizing the CAB menu, it won't render a menu like this, it will just alter the buttons on the existing CAB.
How can I achieve this floating menu along with the selection markers visible, when the EditText is long pressed or double tapped?
Perhaps you can use EditText's getSelectionStart and getSelectionEnd when the OS ActionMode starts (by overriding Activity's onActionModeStarted), then close the OS ActionMode and start your own while manually highlighting the appropriate text using EditText's setSelection.

hardware menu button override for redirecting to page

is possible overade hardware menu button? When i tap on hardware menu button, appear new layout page, instead of view of submenu? My basic app do not have any setting so only what i want is credits page. I try lot of options. I mean something like this:
#override
public boolean onCreateOptionsMenu() {
setContentView(R.layout.credits); }
Every help would be great.
From option menu You must return true for the menu to be displayed; if you return false it will not be shown.
So you can use
#override
public boolean onCreateOptionsMenu() {
setContentView(R.layout.credits);
return false;
}

Android options menu always closes

I would like to know how to prevent the menu bar from closing.
#Override
public void onOptionsMenuClosed(Menu menu) {
}
When the activity starts, I open the menu and want it to stay open.
new Handler().postDelayed(new Runnable() {
public void run() {
openOptionsMenu();
}
}, 1000);
You cannot keep the Options Menu open and it will always act that way. But what you can do is create your own custom menu in a layout.xml and set the visibility to GONE. Then, override the onKeyDown() method and listen for presses of the menu key. If it is pressed, the options menu will be set to open/close (VISIBLE/INVISIBLE) depending on its current state. That way, you can control if the options menu will remain open or not even after touch.

Categories

Resources