Android 7.1原生设置项删除

从源码中看到Settings继承SettingsActivity,而SettingsActivity继承SettingsDrawerActivity,在SettingsDrawerActivity的onCreate方法中,我们看到调用了getDashboardCategories方法,代码:

        getDashboardCategories();//获取设置项列表
        setActionBar(toolbar);
        mDrawerAdapter = new SettingsDrawerAdapter(this);
        ListView listView = (ListView) findViewById(R.id.left_drawer);
        listView.setAdapter(mDrawerAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(android.widget.AdapterView parent, View view, int position,
                    long id) {
                onTileClicked(mDrawerAdapter.getTile(position));
            }
        });

 

跟进到该方法的具体实现:

    public List getDashboardCategories() {
        if (sDashboardCategories == null) {
            sTileCache = new HashMap<>();
            sConfigTracker = new InterestingConfigChanges();
            // Apply initial current config.
            boolean newC =sConfigTracker.applyNewConfig(getResources());
            Log.d(TAG, "newC = " + newC);
            sDashboardCategories = TileUtils.getCategories(this, sTileCache);//重点在这里
        }
        return sDashboardCategories;
    }

跟进到getCategories方法:

    private static final String EXTRA_SETTINGS_ACTION =
            "com.android.settings.action.EXTRA_SETTINGS";

    /**
     * Same as #EXTRA_SETTINGS_ACTION but used for the platform Settings activities.
     */
    private static final String SETTINGS_ACTION =
            "com.android.settings.action.SETTINGS";

    private static final String OPERATOR_SETTINGS =
            "com.android.settings.OPERATOR_APPLICATION_SETTING";

    private static final String OPERATOR_DEFAULT_CATEGORY =
            "com.android.settings.category.wireless";

    private static final String MANUFACTURER_SETTINGS =
            "com.android.settings.MANUFACTURER_APPLICATION_SETTING";

    private static final String MANUFACTURER_DEFAULT_CATEGORY =
            "com.android.settings.category.device";

//以上是TileUtils.java定义的常量

    public static List getCategories(Context context,
            HashMap, Tile> cache) {
        //......省略
        for (UserHandle user : userManager.getUserProfiles()) {
            // TODO: Needs much optimization, too many PM queries going on here.
            if (user.getIdentifier() == ActivityManager.getCurrentUser()) {
                // Only add Settings for this user.
                getTilesForAction(context, user, SETTINGS_ACTION, cache, null, tiles, true);
                getTilesForAction(context, user, OPERATOR_SETTINGS, cache,
                        OPERATOR_DEFAULT_CATEGORY, tiles, false);
                getTilesForAction(context, user, MANUFACTURER_SETTINGS, cache,
                        MANUFACTURER_DEFAULT_CATEGORY, tiles, false);
            }
            if (setup) {
                getTilesForAction(context, user, EXTRA_SETTINGS_ACTION, cache, null, tiles, false);
            }
        }
        //......省略
        return categories;
    }

 

到这里我们就可以看得到,这是根据AndroidManifest.xml对activity及fragement的定义来划分设置项分类的。我们再看一下AndroidManifest.xml对各个activity及fragment的定义,拿个简单的来看看:

        
            
                
                
            
            
            
        

 

这里我们只要前设置项分类去掉就能够删除掉这一设置项,同里如果我们要增加设置项,只要按不同的分类设置参数就行了。

 

 

你可能感兴趣的:(工作学习)