Issue
I am having an issue with WebView
I have changed the contextual text selection menu of WebView
to add some more functionality but the issue which arose due to that is that I lost all the default buttons of WebView
which were
copy , select all , paste , share etc...
I want those buttons to be there and working plus display some extra buttons to achieve my custom functionality which is highlight and add notes etc.
Please let me know how to do this.
Here is my code for modifying the WebView
and adding custom action bar instead of default ActionBar
.
public class CustomWebView extends WebView{
CustomizedSelectActionModeCallback actionModeCallback;
public Context context;
public CustomWebView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
this.context=context;
}
@SuppressLint("NewApi")
@Override
public ActionMode startActionMode(ActionMode.Callback callback) {
// TODO Auto-generated method stub
// ViewParent parent = getParent();
// if (parent == null) {
// return null;
// }
actionModeCallback = new CustomizedSelectActionModeCallback();
return startActionModeForChild(this,actionModeCallback);
}
public class CustomizedSelectActionModeCallback implements ActionMode.Callback{
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.getMenuInflater().inflate(R.menu.contextual_menu, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
mode.setTitle("Select Action");
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.item_delete:
clearFocus();
Toast.makeText(getContext(), "This is my test click", Toast.LENGTH_LONG).show();
break;
case R.id.item_HighLight:
ReaderActivity.btn_ColorChooser.performClick();
break;
default:
break;
}
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
// TODO Auto-generated method stub
clearFocus(); // this is not clearing the text in my device having version 4.1.2
actionModeCallback=null;
}
}
}
Solution
The Solution which i found for this problem was BTSelectionWebView. This is a layer on top of webview which opens a popup menu just like you have in IOS when you select text and the menu appears on top showing options. it really worked like a charm for me
Here is the Link to GitHub Project.
https://github.com/btate/BTAndroidWebViewSelection
Answered By - Umer Kiani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.