Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 不知道为什么我的上升按钮不响_Android_Up Button - Fatal编程技术网

Android 不知道为什么我的上升按钮不响

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

这里我在第二个avticity的oncreate方法上设置了这个

        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这种事经常发生。