Android Long Press on text behavior editing

Is it possible to add something to the list of elements that appear when the user long clicks on any editing text? (Cut, copy paste, select text, select all, input method). I want to add to this an option that scans the QR code and inserts the result into the Edit text. I think it would not be so difficult to get this behavior from the “Text Editing” that I put into my application, but I want to add this parameter to any editing text inside any application on my phone. Is something like this possible, if so, can someone point me in the right direction?

Edit 150 bounty: I want to add an item to the EditText popup dialog when it is pressed for a long time. I want to find a way to make this change system wide, not just in the context of 1 application.

+6
android input android-edittext
source share
3 answers

This is not possible, since the context menu is filled with the applications themselves, and not with the system. You cannot force other applications to have a context element that they may not use in their lives. You can at least have this feature in applications that know about your application.

Create an action that fills and processes only your global menu items. Other applications can use this feature, expanding your activity. But this will also create problems, as other applications will have a strong dependence on your application. Therefore, if your application is not installed on this system, another application will not work. There is also no way to specify this dependency in the manifest file so that the dependent application is hiding in the market if your application is not already installed.

I am sure that this is not the answer you were looking for, but the context menus are designed.

+5
source share

There are two ways: 1st, described by Shahab. The second is simpler. You just need to override the standard method of your activity, for example:

@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { if(view.getId()==R.id.MyEditTextId) { menu.add(Menu.NONE, MyMenu, Menu.NONE, R.string.MyMenuText); } else super.onCreateContextMenu(menu, view, menuInfo); } 

After that, you will see the context menu of the context menu

+3
source share

Yes, you can add something to the list of items in LongClick of EditText.

To put you in the right direction, I post code snippets.

In main.xml do something like

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:id="@+id/textt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> 

After that, do something like

 public class edit extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); EditText text = (EditText)this.findViewById(R.id.textt); text.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { //ADD HERE ABOUT CUT COPY PASTE // TODO Auto-generated method stub return false; } }); } } 

Hope this helps

+1
source share

All Articles