我正在创建一个菜单,以便在webview中长按时显示在屏幕顶部。
但是我收到了一条消息"unfortunately, app has stopped"
,然后应用已关闭。
我在xml(fn.xml)中创建了mymenu并将其放在\res\menu\fn.xml
fn.xml文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.fn.MainActivity" >
<item
android:id="@+id/mark"
android:showAsAction="always"
android:onClick="onContextualMenuItemClicked"
android:title="Mark">
</item>
</menu>
我的MainActivity类代码在
之下public class MainActivity extends ActionBarActivity {
WebView webview;
private ActionMode mActionMode = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webView1);
webview.loadUrl("http://www.myurl.com");
}
@Override
public void onActionModeStarted(ActionMode mode) {
if (mActionMode == null) {
Toast.makeText(getApplicationContext(), "stateVal",
Toast.LENGTH_SHORT).show();
mActionMode = mode;
Menu menu = mode.getMenu();
mode.getMenuInflater().inflate(R.menu.fn, menu);
}
super.onActionModeStarted(mode);
}
public void onContextualMenuItemClicked(MenuItem item) {
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我的日志屏幕截图