Android Error [Attempt to invoke virtual method 'void android.app.ActionBar' on a null object reference]

后端 未结 24 1982
误落风尘
误落风尘 2020-11-28 22:13

I have a code module which implements viewpager with navigation drawer, however, when I run the code I get the following error

01-26 09:20:02.958: D/AndroidR         


        
24条回答
  •  暖寄归人
    2020-11-28 22:51

    The best solution do this in your Oncreate method

     ActionBar actionBar = getSupportActionBar();
    
            if(actionBar != null){
                actionBar.setDisplayHomeAsUpEnabled(true);
            }
    
    

    followed by a new class

    @Override
        public boolean onOptionsItemSelected(MenuItem item) {
    
            int id = item.getItemId();
    
            if(id == android.R.id.home){
                onBackPressed();
                return true;
            }
    
            return super.onOptionsItemSelected(item);
        }
    
    

提交回复
热议问题