public class CustomWebView extends WebView {
private Context context;
private ActionMode mActionmode;
private ActionMode.Callback mActionModeCallback;
private SearchView searchView;
public CustomWebView(Context context){
super(context);
this.context = context;
}
public CustomWebView(Context context, AttributeSet attrs){
super(context,attrs);
this.context = context;
WebSettings webSettings = this.getSettings();
webSettings.setJavaScriptEnabled(true);
this.addJavascriptInterface(new JavaScriptInterface(), "JavaScriptInterface");
this.setOnLongClickListener(new View.OnLongClickListener(){
@Override
public boolean onLongClick(View v) {
if (mActionmode != null)
return false;
mActionmode = startActionMode(mActionModeCallback);
v.setSelected(true);
return true;
}
});
Log.w("test",context.toString());
searchView = ((Activity)context).findViewById(R.id.searchView);
}
我想从活动(customwebview的父视图)中获取searchview。
但此代码生成错误消息。
searchView = ((Activity)context).findViewById(R.id.searchView);
我想调用searchview的方法,但它有空值。