setDisplayHomeAsUpEnabled() not working in PreferenceActivity
You can do it like this
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
You need to call your private method setSupportActionBar()
inside onCreate()
.
Also, you might want to implement onOptionsItemSelected
:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
You forgot to call this method in your onCreate()
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
I have made some assumptions on what you might be trying to achieve. This should work if you want to use a custom toolbar with PreferenceActivity. The following code goes inside onPostCreateView()
LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
mToolBar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root,false);
mToolBar.setTitle(R.string.title);
// insert at top
root.addView(mToolBar, 0);
setSupportActionBar(mToolBar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);