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
Related
My app contains a standard SearchView widget. As you can see from the code below, I am setting an OnClickListener, an OnCloseListener, and an OnQueryTextListener.
If I tap the SearchView, it initially responds as expected. If I enter text and press the search button the keyboard, the OnQueryTextListener fires correctly, and the keyboard is dismissed as per searchView.setIconified(true). However, if I now tap the SearchView again, the OnClickListener is not fired. The keyboard still appears and the field becomes editable, but my code in the OnClickListener is not executed.
If I use the "X" icon to close the search view after this, everything returns to normal. The next time I click on the SearchView, my listener is fired.
I have additional code that I'll need to execute every time the SearchView is clicked.
What could be causing the listener to not fire in this specific instance? Is there something else that I should be doing in OnQueryTextSubmit?
searchView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
filterLayout.setVisibility(View.VISIBLE);
searchView.setIconified(false);
System.out.println("on click");
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
#Override
public boolean onClose() {
filterLayout.setVisibility(View.INVISIBLE);
return false;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
searchView.setIconified(true);
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
I found a half-answer to this problem. If I clear the focus of the searchView when the query is submitted, then when the user next taps the searchView, the OnQueryTextFocusChangeListener gets a call. It doesn't exactly answer my original question, but it's an acceptable workaround for my case.
I have set CustomSelectionActionModeCallback to an edittext as below
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) {
}
};
to disable paste option on edittext,but still user can paste by tapping on the cursor .I tried to create custom edittext class and override canPaste(),but still no luck.Can anybody suggest a correct solution.
Thanks.
Apparently the problem is observed in lollipop+ devices only
Another method one would suggest is to call setLongClickable(false) on the EditText, although that still doesn't prevent pasting from tapping on the cursor.
The proper (or only :) way to do this is to create a custom EditText and override isSuggestionsEnabled and canPaste methods.
Check this answer for an example.
I want to implement my own custom view (not inflating a menu item), I'm planning to use a toolbar to appear each time contextMenu starts, and hide it when finished.
the problem is: there are only answer showing HOW to clear/inflate another menu over the default actionMode menu
what i`ve tried so far:
-> Use a custom contextual action bar for WebView text selection
Overriding the callback at the WebView
#Override
public ActionMode startActionMode(ActionMode.Callback callback) {
callback2 = new customCallBack();
return super.startActionMode(callback2);
}
public class customCallBack implements 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) {
}
}
changing the return false to true, doesn't result in the desired behavior i.e. hide the cab
Overriding the OnLongClick is not a option too, since it disable the current selection.
This answer solves the problem:
android webview: prevent text selection actionMode actionBar
not the most elegant solution ever, but I just tested it in an app I'm building and it works like a charm.
The Only way that worked for me (only on on Android L+) is clearing all the menu items from context actionbar from the activity
#Override
public void onActionModeStarted(ActionMode mode) {
if (mActionMode == null) {
mActionMode = mode;
Menu menu = mode.getMenu();
// Remove the default menu items (select all, copy, paste, search)
menu.clear();
}
Toast.makeText(this, "onActionModeStarted", Toast.LENGTH_SHORT).show();
super.onActionModeStarted(mode);
}
#Override
public void onActionModeFinished(ActionMode mode) {
mActionMode = null;
Toast.makeText(this, "onActionModeFinished", Toast.LENGTH_SHORT).show();
super.onActionModeFinished(mode);
}
inspired by Use a custom contextual action bar for WebView text selection
Also I wasn't able to implement the custom menu usin popupWindow or dialogs or dialog fragments.
So simply put it with the webView in a frame layout and play with its visability and margin
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.
I have a custom menu options that I want to disable it from popping up if a button on screen is clicked..
I thought of using this code but it doesnt work:
#Override
public boolean onPrepareOptionsMenu (Menu menu) {
if (Schedule)
menu.getItem(1).setVisible(View.GONE);
return true;
}
Is there a way to prevent the menu button from doing anything? Thanks.
According to the documentation:
You must return true for the menu to be displayed; if you return false it will not be shown.
So I'm guessing this will work:
#Override
public boolean onPrepareOptionsMenu (Menu menu) {
.... Code .....
return !Schedule;
}
That is assuming that you want the menu to display when Schedule is equal to false.