Show up-Button in actionBar in subscreen preferences

后端 未结 3 833
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 09:30

I\'ve implemented my preferences like shown in the official guidelines.

I have a PreferenceActivity which creates the PreferenceFragment like this:

          


        
3条回答
  •  滥情空心
    2020-12-31 10:36

    To enable the up action do the following:

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    

    this will give you the icon.

    then add

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // Respond to the action bar's Up/Home button
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    

    you can alter this to go where you need to. As another option you can use the navigateUpTo(Intent intent) and the onSupportNavigateUpTo(Intent intent) methods and specify the intent you want to return to.

提交回复
热议问题