好吧,試了很多方法來解決這個問題,但沒有...我想通過菜單項打開選項菜單。openOptionsMenu()不工作
package com.example.tachles;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ShareActionProvider;
public class MainActivity extends AnimActivity {
private ShareActionProvider mShareActionProvider;
ImageView history, contact, info, share;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
history = (ImageView) findViewById(R.id.imageView2);
history.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent history = new Intent(getApplicationContext(),
HistoryMenu.class);
startActivity(history);
}
});
contact = (ImageView) findViewById(R.id.imageView8);
contact.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String recepientEmail = "[email protected]";
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:" + recepientEmail));
startActivity(intent);
}
});
info = (ImageView) findViewById(R.id.imageView9);
info.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent info = new Intent(getApplicationContext(), Odot.class);
startActivity(info);
}
});
}
// Menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actionbar, menu);
// Get the ActionProvider for later usage
mShareActionProvider = (ShareActionProvider) menu.findItem(
R.id.action_share).getActionProvider();
/** Setting a share intent */
mShareActionProvider.setShareIntent(getDefaultShareIntent());
return super.onCreateOptionsMenu(menu);
}
private Intent getDefaultShareIntent() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT,
"תכל'ס - האפליקציה שתלווה אותך לבגרויות");
intent.putExtra(Intent.EXTRA_TEXT,
"https://play.google.com/store/apps/details?id=com.tachles");
return intent;
}
public void Options(MenuItem item){
MainActivity.this.openOptionsMenu();
}
public void like(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_like:
Uri uri = Uri.parse("https://m.facebook.com/tachles.mirnax?_rdr");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}
}
也試過這種方式,它只是什麼也不做...... Android Option Menu on Button click
請幫助...沒有錯誤,沒有logcat的......
這是什麼History_moadim2實現
onClickListener()
? – Sree它是班級名稱。 –
我覺得你沒有寫代碼'onCreateContextMenu()' –