Skip the headers in PreferenceActivity when there's only one header

前端 未结 4 1803
无人共我
无人共我 2020-12-24 07:48

I added preference-headers to my app so that the preference screen would not look broken on Honeycomb and tablet sized ICS. However, I only have one header at the moment so

4条回答
  •  醉话见心
    2020-12-24 08:34

    I don't know if you can specifically skip the header, but this is what I did.

    I created 2 classes, one for Extra Large screen sizes, and one for the rest. EditPreferences.class loads my normal preferences.xml, and the EditPreferencesXLarge.class loads the preference-headers xml.

    public boolean onOptionsItemSelected(MenuItem item) {
        final int SCREENLAYOUT_SIZE_XLARGE = 4;
        final int HONEYCOMB = 11;
        int screenSize = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    
        switch(item.getItemId())
        {
            case R.id.item_prefs:
                if (Build.VERSION.SDK_INT < HONEYCOMB) {
                    startActivity(new Intent(this, EditPreferences.class));
                }
                else if (screenSize < SCREENLAYOUT_SIZE_XLARGE) {
                    startActivity(new Intent(this, EditPreferences.class));
                }
                else {
                    startActivity(new Intent(this, EditPreferencesXLarge.class));
                }
    
                return true;
        }
    
        return (super.onOptionsItemSelected(item));
    }
    

提交回复
热议问题