gpt4 book ai didi

android - 如何在操作栏上添加后退按钮

转载 作者:行者123 更新时间:2023-11-30 03:08:20 26 4
gpt4 key购买 nike

我的应用程序有两个简单的页面 Activity ,我想知道如何使用后退按钮在我的应用程序中添加操作栏

先谢谢你....

我的代码是....

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

web=(WebView)findViewById(R.id.web1);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient());
web.getSettings().setBuiltInZoomControls(true);
web.loadUrl("http://dcs-dof.gujarat.gov.in/live-info.htm");
// web.getProgress();


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

menu.add(0,1,menu.NONE,"About");
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

Toast.makeText(MainActivity.this,"About",Toast.LENGTH_LONG).show();

Intent i=new Intent(MainActivity.this,about.class);
startActivity(i);

return super.onOptionsItemSelected(item);
}



}

最佳答案

如果您的应用程序的目标是 >= API LEVEL 11,您可以使用 native ActionBar,否则您必须使用 SherlockActionBar。要显示“后退按钮”,在第一种情况下:

getActionBar().setDisplayHomeAsUpEnabled(true);

第二种情况

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

@rudys 所述,另一种解决方案可能是使用支持库版本 7 附带的 appcompat。你可以看看here , 以获得更多信息。

关于android - 如何在操作栏上添加后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21399817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com