我四处寻找,但找不到解决问题的方法。我想从我的应用程序中删除菜单硬件键,这样我就可以在操作栏中获得菜单溢出
这是我的代码:
package gridview;
import fragments.MainFragment;
import gab.GlassActionBarHelper;
import hd.light.AboutDev;
import hd.light.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
public class Main extends SherlockFragmentActivity {
private SharedPreferences prefs;
private GlassActionBarHelper helper;
// Starts the Activity for the gridview
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = getSharedPreferences(getResources().getString(R.string.theme_name), 0);
checkBuild();
helper = new GlassActionBarHelper().contentLayout(R.layout.gridview_main);
setContentView(helper.createView(this));
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new MainFragment())
.commit();
}
public void checkBuild() {
int buildNum = prefs.getInt("Build Number", 1);
int currentVersion = 0;
try {
currentVersion = getPackageManager()
.getPackageInfo(getPackageName(), 0).versionCode;
}
catch (NameNotFoundException e) {
e.printStackTrace();
}
if(currentVersion > buildNum) {
getChangelog().show();
Editor editor = prefs.edit();
editor.putInt("Build Number", currentVersion);
editor.commit();
}
}
public Dialog getChangelog()
{
final Dialog CDialog = new Dialog(Main.this);
CDialog.setTitle(getResources().getString(R.string.changelog_title));
CDialog.setContentView(R.layout.changelog);
CDialog.setCanceledOnTouchOutside(true);
CDialog.setCancelable(true);
Button Close = (Button) CDialog.findViewById(R.id.close);
Close.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
CDialog.dismiss();
}
});
return CDialog;
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.shareButton:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_link));
startActivity(Intent.createChooser(shareIntent, "Share Via"));
break;
case R.id.rateButton:
Intent rate = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("market://details?id=your.icons.name.here"));
startActivity(rate);
break;
case R.id.emailButton:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "the1dynasty.android@gmail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getText(R.string.email_subject));
emailIntent.setType("plain/text");
startActivity(Intent.createChooser(emailIntent, "Contact Developer"));
break;
case R.id.aboutButton:
Intent about = new Intent(Main.this, AboutDev.class);
startActivity(about);
break;
case R.id.donateButton:
Intent donate = new Intent(Intent.ACTION_VIEW).setData(Uri.parse
("http://bit.ly/YWwhWu"));
startActivity(donate);
break;
}
return true;
}
}
因为我拥有 Galaxy S4,当我按下菜单按钮时,我从底部弹出。当我在没有菜单按钮的 Nexus 4 模拟器上进行测试时,我得到了想要的结果,操作栏中的菜单溢出(3 个点)。如何从我的应用程序中删除菜单硬件密钥?另外,我按照此处的说明进行操作--->如何在带有菜单按钮的设备上强制使用溢出菜单,但我遇到了一些错误。
有些人可以将此添加到我的代码中并在此处发布整个代码,以便我可以看到我做错了什么?
先感谢您