我想添加一個共享菜單到我的應用程序,從textview 2發送文本到另一個應用程序IE KiK,但目前我無法得到它以識別資源文件作爲菜單繼承人我的代碼:Android:共享菜單,我的菜單inflater無法解析我的資源
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().inflate(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>
變化'android.R.menu.main'到'R.menu.main' –
仍然給我一個錯誤因爲它無法識別菜單 –
閱讀關於如何[製作菜單](http://developer.android.com/guide/topics/ui/menus.html)。菜單xmls是'menu'文件夾的一部分,它們是**不是**活動佈局的一部分。 –