Text Selection in Webview in Android 4.0
<p>This is my code of select text from webview.In this code open dialog box when selection is complete for insert color but in android 4.0 they give inbuilt selection tool with copy,share,websearch so how i find press event of copy,share etc.. so i open dialog when copy is pressed..</p>

<p>Or if this event not get then how i hide default Selection tool of 4.0 through code in my android application.</p>

<p>Please Help me..
Thanks in Advance...</p>

<pre><code>    if (event.getAction() == android.view.MotionEvent.ACTION_DOWN &amp;&amp;   isSelecting         &amp;&amp;          !selectStart) 
       {
    selectStart = true;
    // Log.e("touch event", "Touch start event points:- "+
    // event.getRawX()+" "+ event.getRawY() );
    touch_startx = event.getRawX();
    // touch_starty = event.getRawY();
    Log.i("TouchTest", "start:"+String.valueOf(touch_startx));
    emulateShiftHeld(bookdatawebview);

       } 
       else if (event.getAction() == android.view.MotionEvent.ACTION_UP &amp;&amp; isSelecting &amp;&amp;       selectStart) 
       {

    isSelecting = false;
    selectStart = false;
    mScrollView.setScrollingEnabled(true);
    emulateShiftHeldUp(bookdatawebview);
    touch_starty = event.getRawY();
    Log.i("TouchTest", "end:"+String.valueOf(touch_starty));

    Log.i("BookData","Record Count : "+highlightedWords.size());
    for(int i=0;i&lt;highlightedWords.size();i++)
    {

        Log.i("BookData","DB Text : "+highlightedWords.get(i).text+" : Selected Text : "+app.selectedtext);
        if(highlightedWords.get(i).text.contains(app.selectedtext))
        {

            DeleteHighlightText = highlightedWords.get(i).text;
            Log.i("BookData","Selected text found in DB");
            textSelected = true;
            Toast.makeText(BookData.this, "This text is highlighted", Toast.LENGTH_SHORT).show();
            highlightedWords.remove(i);
            break;
        }
    }

    //insert query existing functionality
    highlightdialog.setContentView(R.layout.highlightandsharedialog);

    // dialog.setTitle("Select a Font");
    Window window = highlightdialog.getWindow();
    window.setGravity(Gravity.CENTER);
    window.setLayout(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

    highlightdialog.show();
    }

private void emulateShiftHeldUp(WebView view) 
{
    try 
    {

        shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_UP,KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);

        shiftPressEvent.dispatch(view);

        Log.e("Application", mclipboard.getText().toString());

        app.selectedtext = mclipboard.getText().toString();

    }
    catch (Exception e) 
    {
            Log.e("dd", "Exception in emulateShiftHeld()", e);
    }
}

private void emulateShiftHeld(WebView view) 
{
    try 
    {


        shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);

        shiftPressEvent.dispatch(view);

        app.selectedtext = mclipboard.getText().toString();

    } 
    catch (Exception e) 
    {
            Log.e("dd", "Exception in emulateShiftHeld()", e);
    }
}
</code></pre>
