Android 不知道为什么我的上升按钮不响
这里我在第二个avticity的oncreate方法上设置了这个Android 不知道为什么我的上升按钮不响,android,up-button,Android,Up Button,这里我在第二个avticity的oncreate方法上设置了这个 super.onCreate(savedInstanceState); // Actionbar getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.new_message); 这是OnOptions ItemSelected public boolean onOptio
super.onCreate(savedInstanceState);
// Actionbar
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.new_message);
这是OnOptions ItemSelected
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_save) {
Intent newMessage = new Intent(getApplicationContext(),NewMessage.class);
startActivity(newMessage);
}
if(id == R.id.home){
Toast.makeText(getApplicationContext(), "Home button click", 2000).show();
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
/* return super.onOptionsItemSelected(item);*/
return true;
}
是否需要在其他地方(如清单或其他地方)进行更改MainActivity上没有备份活动的代码问题:
if(id == R.id.home)
if(id == android.R.id.home)
您正在使用项目的R java中的id,该id肯定会返回false。它应该是本地android home,而不是您的R生成的home id
解决方案:
if(id == R.id.home)
if(id == android.R.id.home)
感谢它所做的小错误,使最大的错误problem@Kirtesh这种事经常发生。