Show up/back button on android nested PreferenceScreen?

前端 未结 3 942
情歌与酒
情歌与酒 2021-01-02 01:58

I have a two level PreferenceScreen:


general settings
   
   more advanced sett         


        
3条回答
  •  离开以前
    2021-01-02 02:24

    This may be more work, but you could create two PreferenceAtivity files each with their own PreferenceFragment. Each PreferenceFragment will have its own PreferenceScreen XML (the first level screen, and the second. level screen). From the firsts level screen you launch the second PreferenceActivity with an Intent within the tag. In the second PreferenceActivity you can set the home icon by doing this:

    ActionBar bar = getActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    

    and then also had a handler for the home button:

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
    
        return false;
    }
    

    Assets:

    FirstPreferenceActivty
    FirstPreferenceFragment
    pref_first.xml (layout with PreferenceScreen and Prefernce nodes)
    
    SecondPreferenceActivty
    SecondPreferenceFragment
    pref_second.xml (layout with PreferenceScreen and Prefernce nodes)
    

提交回复
热议问题