I'm having trouble with making custom EditText component. I want copy/paste/select all feature to be fully prevented.
Long click case is easy to prevent.
But there are 2 cases I've also seen which opens the menu and I'm having troubles with.
Double tap EditText (can be blocked for example to eat douple tap event)
But this removes the selection mode feature.
Some devices launch the menu when just clicking insert controller.
So I want to have insertion and selection controllers visible and usable, but the HandleView menu to be never shown.
Do I have to copy paste and override TextView class or is there simplier hack solution for this.
Br,
Niko
Related
Is it possible to easily show a simple menu, similar to this one in a screenshot from Chrome? I want a menu to show when there is a selection to manipulate to allow the user to Slect All, Cut, Copy, Paste.
Is this a standard control or something that should be easy to get working? What is the name of this control. This control is not showing automatically for our custom EditText view, which is fully functional in every other way.
Will I have to create my own custom control and display it in the correct location, manually? I have done similar work for an equivalent custom control in iOS, where the menu I want is called an Edit Menu, and it is trivial to show and hide that menu.
Similar questions, such as How do I enable standard copy paste for a TextView in Android?, have appeared on StackOverflow in the past and the standard answer is to add the android:textIsSelectable property to your TextView. This allows the text to be selected after short or long pressing but the copy menu does not immediately appear. Instead, you need to lift your finger and then long press a second time on the selected text in order for this menu to appear.
Is it possible to make it so that the copy menu appears after the initial text selection instead of after the second long press?
Is there any way to programmatically start contextual action bar associated with a text view, on a button click? It should contain default options of copy/select all as well.
Basically, I want to show the selection handles in my text view and the android default copy/select all option in action bar, on a button click (instead of long click/double tap).
What I tried so far:
tried using the setCustomActionModeCallback() api, but problem here, is user need to long press/double click the text view for CAB to appear.
Tried using startActionMode() api, but could not find a way to retain default items.. it just opens a new empty CAB.. I know, I can add my custom copy-select all code and make use of this empty CAB, but I want to use the default Android provided one instead of managing it by myself.
Edit; I can't use EditText. The view need to be TextView only and long click will be disabled. I am doing all the above changes by setting TextView as selectable
Select your text manually and then perform a long click:
textView.post(new Runnable() {
#Override
public void run() {
Selection.selectAll((Spannable) tv.getText());
tv.performLongClick();
}
});
Edit:
The problem is that the built-in text selection CAB is private and uses multiple private classes. You'd need to copy a lot of code or access a bunch of methods with reflection to use it.
You could make your own CAB menu but you'd also need the controller handles which is again a lot of code.
A simple solution would be to live with what you have and use my above suggested method. If you want to avoid calling your long click listener you can remove it while calling the cab:
Selection.selectAll((Spannable) tv.getText());
tv.setOnLongClickListener(null);
tv.performLongClick();
tv.setOnLongClickListener(mLongClickListener);
if you want to select text in your text View than there are several approaches that you can follow.
first thing you can do, is set the xml properties of TextView.
android:textIsSelectable = "true"
txtView.setTextIsSelectable(true)
The textIsSelectable flag allows users to make selection gestures in the TextView, which in turn triggers the system's built-in copy/paste controls.
or
android:selectAllOnFocus = true;
setSelectAllOnFocus(boolean)
If the text is selectable, select it all when the view takes focus. and you can set the focus on click of your Button. using RequestFocus() method.
for more detail study you can reference to this Link. you will find all your Required task done.
http://developer.android.com/reference/android/widget/TextView.html[http://developer.android.com/reference/android/widget/TextView.html][1]
thank you
Is there a way to find out when did a user click "Setting" options on the screen menu?
The onClick listner's KeyDown events catches only the hardware buttons on the phone and not the clicks of the sofware keyboard that shows up when a textbox/editText gets a focus and the key guard shows up.
Is it even possible using public android SDK.
P.S. : I am only concerned with 2.2 and 2.3 so its fine if this is not possible on 3.0 and above.
Thnx
EDIT
Explanation of a scenario that will help understand the question better!
I have a full screen activity with a editText and a button. I want to intercept all the clicks that a user make and based on that make some decisions.
I am able to register a listner to intercept what phisical keys are being clicked(HOME, MENU, VOLUME UP/DOWN etc)...The problem is, when the user clicks on the editText i.e. the text box gets the focus, the sotware keypad shows up. Now I also want to intercept what keys(numbers, alphabets, special characters or even custom functions on some samsung android phone like 'Go To Settings' are clicked and perform action based on the clicks.
My question is, is it possible and if yes, then how?
NOTE: Please dont ask me why am I doing this because its bad user experience. I am very much aware of that. I am trying to do this in a particular context that needs this functionality. Thnx!
You need to use the KeyListener class and setKeyListener
http://developer.android.com/reference/android/widget/TextView.html
This only allows you to modify/filter input into the TextView.
I would like to add a button in android when a user selects texts then clicks the context button (e.g. it shows copy, cut, paste, select all). Can someone please direct me to the libraries or some resource where I can potentially learn about this?
Trying to search for it, I'm kind of lost because I really don't even know where to start. Does android provide a direct library to access this? If so, in what namespace might I find these functions?
Thank you!
I would like to add a button in android when a user selects texts then clicks the context button (e.g. it shows copy, cut, paste, select all).
There is no "context button" in Android.
On an EditText widget, "Cut, Copy, Paste, Select All" is displayed in one of three ways:
Via a context menu. You can attempt to add menu items to this menu via onCreateContextMenu().
Via an action mode on Android 3.0+. You can call setCustomSelectionActionModeCallback() on the EditText to add new items to the action mode. Note that the action mode is not always displayed, due to either a bug or an inexplicable UI decision.
Via something else, as some Android 2.x device manufacturers elected to do their own thing for cut/copy/paste with an EditText that is not a context menu.
For copy and paste you can simply use-
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.getText() / clipboard.setText(yourText);
Just implement above lines on click of your button. And this is for Context Menus.