0
我想在點擊操作欄中的共享圖標後調用一個活動。爲此我 創建一個名爲'flip'的菜單,其中包含一個名爲'menu_share'的項目,用於Android 2.2+。翻轉菜單在名爲'ShareActivity'
的第一項活動中被誇大。在此之後,我想在操作欄中單擊shareicon
後調用其他活動,但圖標沒有響應。ShareActionProvider不可點擊
菜單xml文件的代碼。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto=" >
<item android:id="@+id/menu_share"
android:title="share"
android:icon="@drawable/shar"
yourapp:showAsAction="ifRoom"
yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider" />
</menu>
第一次活動的代碼。
public class ShareActivity extends ActionBarActivity {
SocialAuthAdapter adapter;
EditText edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
ActionBar ab=getSupportActionBar();
ab.setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
ab.setDisplayHomeAsUpEnabled(true);
ab.setDisplayShowTitleEnabled(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.flip, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case android.R.id.home:
super.onBackPressed();
return true;
case R.id.menu_share:
startActivity(new Intent(this,ShActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
感謝您的解決方案 – Vishwajeet
@Vishwajeet,我有一個類似的問題,除了我想使用默認的共享行爲。當我添加ShareActionProvider時,我不能再點擊共享圖標。任何想法爲什麼發生這種情況? – snapplex
@snapplex,我建議用相關的代碼創建一個新問題。 –