ContextMenu 显示我未在 context_menu.xml 中指定的项目
我是一个安卓菜鸟。我正在使用 MyEclipse、ADT、SDK、Android 2.2、API 8。
我的 Activity 看起来像这样 -
package com.vvittal.relativelayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class Login extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
registerForContextMenu(findViewById(R.id.uEntry));
registerForContextMenu(findViewById(R.id.pwdEntry));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.login_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.agency_item: System.out.println("----------------");
return true;
case R.id.prod_cat_item: System.out.println("++++++++++++++++");
return true;
default: return super.onOptionsItemSelected(item);
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
//menu.f
//menu.setHeaderTitle("Your Options");
}
@Override
public boolean onContextItemSelected(MenuItem item){
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.option1: ;
return true;
case R.id.option2:
return true;
default:
int i = item.getItemId();
return super.onContextItemSelected(item);
}
}
}
我的 AndroidManifest.xml 看起来像这样 -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vvittal.relativelayout"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Login"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
context_menu.xml 如下 -
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/option1"
android:title="@string/yes" />
<item android:id="@+id/option2"
android:title="@string/no" />
</menu>
我的模拟器上的菜单有一个名为“的项目”输入法”,以及我在 XML 中指定的“是”和“否”。
我想知道当我没有在 xml 中指定任何内容时,这个附加项“输入法”来自哪里?另外如何以编程方式删除它?
I'm an Android noob. I'm working with MyEclipse, ADT, SDK, Android 2.2, API 8.
My Activity looks like this -
package com.vvittal.relativelayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class Login extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
registerForContextMenu(findViewById(R.id.uEntry));
registerForContextMenu(findViewById(R.id.pwdEntry));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.login_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.agency_item: System.out.println("----------------");
return true;
case R.id.prod_cat_item: System.out.println("++++++++++++++++");
return true;
default: return super.onOptionsItemSelected(item);
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
//menu.f
//menu.setHeaderTitle("Your Options");
}
@Override
public boolean onContextItemSelected(MenuItem item){
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.option1: ;
return true;
case R.id.option2:
return true;
default:
int i = item.getItemId();
return super.onContextItemSelected(item);
}
}
}
And my AndroidManifest.xml look like this -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vvittal.relativelayout"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Login"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The context_menu.xml is as below -
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/option1"
android:title="@string/yes" />
<item android:id="@+id/option2"
android:title="@string/no" />
</menu>
The menu on my emulator has an item called "Input Method", in addition to "Yes" and "No" that I have specified in XML.
I'd like to know where this additional item "Input Method" is coming from when I have not specified any in the xml? Also how to I remove it programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
操作系统将添加适合该小部件的上下文菜单选项。对于
EditText
小部件,这将包括剪切、复制、粘贴、全选和选择输入法等操作。请不要。首先,它们是为了帮助用户。其次,它们是平台的标准配置,如果不可用,用户可能会感到恼火。
The operating system will add context menu choices as appropriate for the widget. In the case of
EditText
widgets, this will include things like cut, copy, paste, select all, and choosing an input method.Please don't. First, they are there to help the user. Second, they are standard for the platform, and users may get irritated if they are not available.