Search code examples
javaandroidandroid-actionbarandroid-support-libraryandroid-appcompat

cannot resolve method getSupportActionBar().setDisplayHomeAsUpEnabled(true);


I am using Android Studios, however, I am unable to add the below two methods as it says that it cannot resolve them.

 getSupportActionBar().setDisplayHomeAsUpEnabled(true);

  getSupportActionBar().setTitle("Detail")

;


Solution

  • Your issue is that you are not extending the AppCompatActivity:

    Change:

     public class First extends FragmentActivity
    

    with:

     public class First extends AppCompatActivity
    

    As you can check in the doc the getSupportActionBar() method depends on the AppCompatActivity.