Java Android:共享菜单,我的菜单膨胀器无法解析我的资源
我正在尝试向我的应用程序添加一个共享菜单,该菜单将文本从textview 2发送到另一个应用程序,即KiK,但目前我无法让它识别资源文件,因为菜单下面是我的代码:Java Android:共享菜单,我的菜单膨胀器无法解析我的资源,java,android,xml,Java,Android,Xml,我正在尝试向我的应用程序添加一个共享菜单,该菜单将文本从textview 2发送到另一个应用程序,即KiK,但目前我无法让它识别资源文件,因为菜单下面是我的代码: public class ME extends Activity { /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {
public class ME extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(android.R.menu.main, menu);
MenuItem shareItem = menu.findItem(R.id.action_share);
ShareActionProvider mShare = (ShareActionProvider)shareItem.getActionProvider();
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hi");
mShare.setShareIntent(shareIntent);
return super.onCreateOptionsMenu(menu);
}
}
getMenuInflater()充气(android.R.menu.main,menu)问题出在哪里
和我的XML资源文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:="@+id/TextView 1"
android:orientation="vertical"
android:layout_width="400dp"
android:layout_height="300dp" >
</TextView>
<TextView
android:="@+id/TextView 2"
android:orientation="vertical"
android:layout_width="400dp"
android:layout_height="300dp" >
</TextView>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_share"
android:orderInCategory="100"
android:icon="@drawable/ic_menu_share"
android:actionProviderClass= "android.widget.ShareActionProvider" />
</menu>
</LinearLayout>
Changeandroid.R.menu.main
改为R.menu.main
,这仍然会给我一个错误,因为它无法识别menuRead,无法了解如何识别。菜单xml是菜单
文件夹的一部分,它们不是活动布局的一部分。share.xml不应位于名为Menu的文件夹中。大家好,谢谢你们的帮助我解决了我的问题干杯:D
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_share"
android:orderInCategory="100"
android:icon="@drawable/ic_menu_share"
android:actionProviderClass= "android.widget.ShareActionProvider"
/>
</menu>
getMenuInflater().inflate(R.menu.main, menu);