android框架_5.0的Settings模块的分析2_009

本文深入剖析了SettingsActivity类,包括其继承的接口与类的作用、关键字段的用途、仪表板加载逻辑及配置文件等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

5.0的Settings模块的分析2

一、继续上篇,来整体分析一个类:SettingsActivity.java

public class SettingsActivity extends Activity
        implements PreferenceManager.OnPreferenceTreeClickListener,
        PreferenceFragment.OnPreferenceStartFragmentCallback,
        ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
        SearchView.OnQueryTextListener, SearchView.OnCloseListener,
        MenuItem.OnActionExpandListener {


    private static final String LOG_TAG = "Settings";


    ///M: change backup reset title
    private ISettingsMiscExt mExt;

 

1、首先来看看继承了哪些接口和类,这些接口和类有什么作用,这是首先要知道的!

 

2、PreferenceManager.OnPreferenceTreeClickListener接口,是设置中选项的点击监听事件接口,

3、PreferenceFragment.OnPreferenceStartFragmentCallback接口,是启动一个fragment之后的回调接口

4、ButtonBarHandler接口,是判断是否有下一个按钮和获取下一个按钮控件的接口;

5、FragmentManager.OnBackStackChangedListener接口,是按返回堆栈改变的接口;

6、SearchView.OnQueryTextListener接口,是用在搜索界面输入字符时激发该接口的;

7、SearchView.OnCloseListener接口,是在搜索界面关闭时,需要执行的接口;

8、MenuItem.OnActionExpandListener接口,是在右上方菜单展开和隐藏时需要执行的接口;

9、 private ISettingsMiscExt mExt该对象是扩展对象;

 

    // Constants for state save/restore
    private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
    private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
    private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
    private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
    private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
    private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";

10、以上的常量是用来保存和恢复状态的,在onSaveInstanceState(Bundle outState)函数中保存,onCreate(Bundle savedState) 方法中使用;

11、":settings:categories"是用于存储类别,也就是显示的条目的;

   ":settings:search_menu_expanded"用于存储搜索展开的菜单字段;

   ":settings:search_query",存储查询的字段;

   ”:settings:show_home_as_up“,存储左上角是否有小图标的字段;

   ":settings:show_search",显示搜索的结果;

   ":settings:home_activities_count",显示launcher home activity的个数;一般只有一个,也可能有多个

    /**
     * When starting this activity, the invoking Intent can contain this extra
     * string to specify which fragment should be initially displayed.
     * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
     * will call isValidFragment() to confirm that the fragment class name is valid for this
     * activity.
     */
    public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";

    /**
     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
     * this extra can also be specified to supply a Bundle of arguments to pass
     * to that fragment when it is instantiated during the initial creation
     * of the activity.
     */
    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";

12、上面两个一个存储fragment,一个是存储传递给fragment的参数args;

    // extras that allow any preference activity to be launched as part of a wizard

    // show Back and Next buttons? takes boolean parameter
    // Back will then return RESULT_CANCELED and Next RESULT_OK
    protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";

    // add a Skip button?
    private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";

    // specify custom text for the Back or Next buttons, or cause a button to not appear
    // at all by setting it to null
    protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
    protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";

    

13、这是在第一次开机之后,授权机器进入设置界面wifi界面,传来的字段;

"extra_prefs_show_button_bar":是否显示按钮条,

"extra_prefs_show_skip":是否显示跳过

"extra_prefs_set_next_text":是否显示下一步

"extra_prefs_set_back_text":是否显示返回

 

    /**
     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
     * those extra can also be specify to supply the title or title res id to be shown for
     * that fragment.
     */
    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
    /**
     * The package name used to resolve the title resource id.
     */
    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
            ":settings:show_fragment_title_res_package_name";
    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
            ":settings:show_fragment_title_resid";
    public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
            ":settings:show_fragment_as_shortcut";

    public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
            ":settings:show_fragment_as_subsetting";

    private static final String META_DATA_KEY_FRAGMENT_CLASS =
        "com.android.settings.FRAGMENT_CLASS";

    private static final String EXTRA_UI_OPTIONS = "settings:ui_options";

    private static final String EMPTY_QUERY = "";/**
     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
     * those extra can also be specify to supply the title or title res id to be shown for
     * that fragment.
     */
    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
    /**
     * The package name used to resolve the title resource id.
     */
    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
            ":settings:show_fragment_title_res_package_name";
    public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
            ":settings:show_fragment_title_resid";
    public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
            ":settings:show_fragment_as_shortcut";

    public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
            ":settings:show_fragment_as_subsetting";

    private static final String META_DATA_KEY_FRAGMENT_CLASS =
        "com.android.settings.FRAGMENT_CLASS";

    private static final String EXTRA_UI_OPTIONS = "settings:ui_options";

    private static final String EMPTY_QUERY = "";

14、 ":settings:show_fragment_title":表示从外部传过来的fragment标题字段;

":settings:show_fragment_title_res_package_name":表示显示fragment的包名名称

 ":settings:show_fragment_title_resid":表示获取fragment的标题资源id

":settings:show_fragment_as_shortcut":表示从shortcut中传过来的字段,也就是launcher界面的快捷方式

":settings:show_fragment_as_subsetting":表示子设置

"com.android.settings.FRAGMENT_CLASS":表示fragment的类名

"settings:ui_options":表示ui的选择选项,应该不对,真是不知道是什么,getWindow会用到;

 

    // Show only these settings for restricted users
    private int[] SETTINGS_FOR_RESTRICTED = {
            R.id.wireless_section,
            R.id.wifi_settings,
            R.id.bluetooth_settings,
            ......
            R.id.home_settings,
            R.id.dashboard,
            R.id.power_settings,
            R.id.hotknot_settings
    };
   private static final String[] ENTRY_FRAGMENTS = {
            WirelessSettings.class.getName(),
            WifiSettings.class.getName(),
            AdvancedWifiSettings.class.getName(),
            ......
            HotKnotSettings.class.getName(),
            AudioProfileSettings.class.getName(),
            WfdSinkSurfaceFragment.class.getName(),
            WifiGprsSelector.class.getName(),
            SoundEnhancement.class.getName(),
    };

15、宏SETTINGS_FOR_RESTRICTED是显示板上的资源id,ENTRY_FRAGMENTS是保存的fragment的名称,对外公布的名称;

    private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
            "android.settings.APPLICATION_DETAILS_SETTINGS"
    };

16、是从launcher界面传过来的数组字段;

 

二、继续一,来分析一个类:SettingsActivity.java中的onCreate方法;

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    mExt = UtilsExt.getMiscPlugin(this);//通过插件获取ISettingsMiscExt对象
    mIsWifiOnly = Utils.isWifiOnly(this);//判断是否只支持wifi;

    // Should happen before any call to getIntent()
    getMetaData();//获取mFragmentClass的名称,也就是需要显示的fragment名称

    final Intent intent = getIntent();//获取intent对象,
    if (intent.hasExtra(EXTRA_UI_OPTIONS)) {//判断是否需要设置uiOptions值
        getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
    }

    mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
            Context.MODE_PRIVATE);
    //初始化的fragment的名称
// Getting Intent properties can only be done after the super.onCreate(...) 
final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);       
 //获取是否有从launcher快捷方式传过来的字段属性值 
 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) 
 || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);        
 //组装获取className 
 final ComponentName cn = intent.getComponent(); 
 final String className = cn.getClassName();       
 
 //是否需要显示仪表板,也就是设置中的选项主界面; 
 mIsShowingDashboard = className.equals(Settings.class.getName());

1、上面这一段,基本上都是初始化的一些信息;

 

// This is a "Sub Settings" when:
// - this is a real SubSettings
// - or :settings:show_fragment_as_subsetting is passed to the Intent
//获取是否有子设置的fragment传递过来
final boolean isSubSettings = className.equals(SubSettings.class.getName()) ||
        intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
// If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
   //如果有显示子设置,则获取主题资源id,并设置子设置的主题资源
if (isSubSettings) {
   // Check also that we are not a Theme Dialog as we don't want to override the
   final int themeResId = getThemeResId();
   if (themeResId != R.style.Theme_DialogWhenLarge &&
            themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
   setTheme(R.style.Theme_SubSettings); 
  } 
}
 //是显示仪表板选项界面,还是加载的fragment界面 
 setContentView(mIsShowingDashboard ? R.layout.settings_main_dashboard :
    R.layout.settings_main_prefs);        
 //此视图是加载
fragment的 mContent = (ViewGroup) findViewById(R.id.main_content); 
getFragmentManager().addOnBackStackChangedListener(this);        
//更新index
 if (mIsShowingDashboard) { 
 	Index.getInstance(getApplicationContext()).update();
 }

 

2、代码加载布局资源;

 

        if (savedState != null) {
            // We are restarting from a previous saved state; used that to initialize, instead
            // of starting fresh.
            mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
            mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);

            setTitleFromIntent(intent);

            ArrayList<DashboardCategory> categories =
                    savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
            if (categories != null) {
                mCategories.clear();
                mCategories.addAll(categories);
                setTitleFromBackStack();
            }

            mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
            mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
                    1 /* one home activity by default */);
        }

3、以上是比较简单的,获取从intent获取值;如果savestate不为null的情况下;

        } else {
            if (!mIsShowingDashboard) {//是否显示仪表板,也就是选项板,否:进入if
                // Search is shown we are launched thru a Settings "shortcut". UP will be shown
                // only if it is a sub settings
                if (mIsShortcut) {
                    mDisplayHomeAsUpEnabled = isSubSettings;
                    mDisplaySearch = false;
                } else if (isSubSettings) {
                    mDisplayHomeAsUpEnabled = true;
                    mDisplaySearch = true;
                } else {
                    mDisplayHomeAsUpEnabled = false;
                    mDisplaySearch = false;
                }
                setTitleFromIntent(intent);
          //获取fragment并设置它
                Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
                switchToFragment(initialFragmentName, initialArguments, true, false,
                        mInitialTitleResId, mInitialTitle, false);
            } else {
                // No UP affordance if we are displaying the main Dashboard
                mDisplayHomeAsUpEnabled = false;
                // Show Search affordance
                mDisplaySearch = true;
                mInitialTitleResId = R.string.dashboard_title;//显示仪表板
                switchToFragment(DashboardSummary.class.getName(), null, false, false,
                        mInitialTitleResId, mInitialTitle, false);
            }
        }  } else {
            if (!mIsShowingDashboard) {//是否显示仪表板,也就是选项板,否:进入if
                // Search is shown we are launched thru a Settings "shortcut". UP will be shown
                // only if it is a sub settings
                if (mIsShortcut) {
                    mDisplayHomeAsUpEnabled = isSubSettings;
                    mDisplaySearch = false;
                } else if (isSubSettings) {
                    mDisplayHomeAsUpEnabled = true;
                    mDisplaySearch = true;
                } else {
                    mDisplayHomeAsUpEnabled = false;
                    mDisplaySearch = false;
                }
                setTitleFromIntent(intent);
          //获取fragment并设置它
                Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
                switchToFragment(initialFragmentName, initialArguments, true, false,
                        mInitialTitleResId, mInitialTitle, false);
            } else {
                // No UP affordance if we are displaying the main Dashboard
                mDisplayHomeAsUpEnabled = false;
                // Show Search affordance
                mDisplaySearch = true;
                mInitialTitleResId = R.string.dashboard_title;//显示仪表板
                switchToFragment(DashboardSummary.class.getName(), null, false, false,
                        mInitialTitleResId, mInitialTitle, false);
            }
        }

4、上面就是做了一件事情,显示相应的fragment;默认显示DashboardSummary.java类;

        mActionBar = getActionBar();
        if (mActionBar != null) {
            mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
            mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
        }
        mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);

5、初始化上面的actionBar,也就是设置中的状态栏;

   // see if we should show Back/Next buttons,这是第一次开机需要联网进入的设置界面,由外部传入的
    if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {

        View buttonBar = findViewById(R.id.button_bar);
        if (buttonBar != null) {
            buttonBar.setVisibility(View.VISIBLE);

            Button backButton = (Button)findViewById(R.id.back_button);
            backButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    setResult(RESULT_CANCELED, getResultIntentData());
                    finish();
                }
            });
            Button skipButton = (Button)findViewById(R.id.skip_button);
            skipButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    setResult(RESULT_OK, getResultIntentData());
                    finish();
                }
            });
            mNextButton = (Button)findViewById(R.id.next_button);
            mNextButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    setResult(RESULT_OK, getResultIntentData());
                    finish();
                }
            });

            // set our various button parameters
            if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    mNextButton.setVisibility(View.GONE);
                }
                else {
                    mNextButton.setText(buttonText);
                }
            }
            if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    backButton.setVisibility(View.GONE);
                }
                else {
                    backButton.setText(buttonText);
                }
            }
            if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
                skipButton.setVisibility(View.VISIBLE);
            }
        }
    }
		//获取HomeActivity的个数
    mHomeActivitiesCount = getHomeActivitiesCount();
}

 

6、显示上一步、下一步的代码多,这里不做讨论;

 

   /**
     * Called when the activity needs its list of categories/tiles built.
     *
     * @param categories The list in which to place the tiles categories.
     */
    private void buildDashboardCategories(List<DashboardCategory> categories) {
        categories.clear();//清空仪表板上的选项
        //加载dashboard_categories.xml文件中的选项
        loadCategoriesFromResource(R.xml.dashboard_categories, categories);
        //根据判断加载list选项
        updateTilesList(categories);
    }

 

7、这个方法就是加载仪表板上的显示内容;

 

 

三、下面来分析配置文件:dashboard_categories.xml

<!-- WIRELESS and NETWORKS 无线和网络-->
<dashboard-category
        android:id="@+id/wireless_section"
        android:title="@string/header_category_wireless_networks" >

    <!-- Wifi Wi-Fi-->
    <dashboard-tile
            android:id="@+id/wifi_settings"
            android:title="@string/wifi_settings_title"
            android:fragment="com.android.settings.wifi.WifiSettings"
            android:icon="@drawable/ic_settings_wireless"
            />

    <!--HetComm 涡轮下载-->
    <dashboard-tile
            android:id="@+id/hetcomm_settings"
            android:icon="@drawable/ic_settings_hetcomm"
            android:title="@string/hetcom_setting_title">
        <intent android:action="com.android.settings.HETCOMM_SETTINGS" />
    </dashboard-tile>

    <!-- Bluetooth 蓝牙-->
    <dashboard-tile
            android:id="@+id/bluetooth_settings"
            android:title="@string/bluetooth_settings_title"
            android:fragment="com.android.settings.bluetooth.BluetoothSettings"
            android:icon="@drawable/ic_settings_bluetooth2"
            />
            
    <!-- Hotknot 热点-->
    <dashboard-tile
            android:id="@+id/hotknot_settings"
            android:title="@string/hotknot_settings_title"
            android:fragment="com.mediatek.settings.hotknot.HotKnotSettings"
            android:icon="@drawable/ic_settings_hotknot" 
            />

    <!-- SIM Cards SIM卡-->
    <dashboard-tile
            android:id="@+id/sim_settings"
            android:title="@string/sim_settings_title"
            android:fragment="com.android.settings.sim.SimSettings"
            android:icon="@drawable/ic_sim_sd"
            />

    <!-- Data Usage 流量使用情况-->
    <dashboard-tile
            android:id="@+id/data_usage_settings"
            android:title="@string/data_usage_summary_title"
            android:fragment="com.android.settings.DataUsageSummary"
            android:icon="@drawable/ic_settings_data_usage"
            />

    <!-- Operator hook -->
    <dashboard-tile
            android:id="@+id/operator_settings"
            android:fragment="com.android.settings.WirelessSettings" >
        <intent android:action="com.android.settings.OPERATOR_APPLICATION_SETTING" />
    </dashboard-tile>

    <!-- Other wireless and network controls 更多-->
    <dashboard-tile
            android:id="@+id/wireless_settings"
            android:title="@string/radio_controls_title"
            android:fragment="com.android.settings.WirelessSettings"
            android:icon="@drawable/ic_settings_more"
            />

</dashboard-category>

 

1、设置“无线与网络的”选项的仪表板;

 

 

<!-- DEVICE 设备-->
<dashboard-category
        android:id="@+id/device_section"
        android:title="@string/header_category_device" >

    <!-- Home 主屏幕-->
    <dashboard-tile
            android:id="@+id/home_settings"
            android:title="@string/home_settings"
            android:fragment="com.android.settings.HomeSettings"
            android:icon="@drawable/ic_settings_home"
            />

    <!-- Display 显示-->
    <dashboard-tile
            android:id="@+id/display_settings"
            android:title="@string/display_settings"
            android:fragment="com.android.settings.DisplaySettings"
            android:icon="@drawable/ic_settings_display"
            />

    <!-- Notifications 提示音和通知-->
    <dashboard-tile
            android:id="@+id/notification_settings"
            android:title="@string/notification_settings"
            android:fragment="com.mediatek.audioprofile.AudioProfileSettings"
            android:icon="@drawable/ic_settings_notifications"
            />

    <!-- Storage 存储-->
    <dashboard-tile
            android:id="@+id/storage_settings"
            android:title="@string/storage_settings"
            android:fragment="com.android.settings.deviceinfo.Memory"
            android:icon="@drawable/ic_settings_storage"
            />

    <!-- Battery 电池-->
    <dashboard-tile
            android:id="@+id/battery_settings"
            android:title="@string/power_usage_summary_title"
            android:fragment="com.android.settings.fuelgauge.PowerUsageSummary"
            android:icon="@drawable/ic_settings_battery"
            />

    <!-- Application Settings 应用-->
    <dashboard-tile
            android:id="@+id/application_settings"
            android:title="@string/applications_settings"
            android:fragment="com.android.settings.applications.ManageApplications"
            android:icon="@drawable/ic_settings_applications"
            />

    <!-- Manage users 用户-->
    <dashboard-tile
            android:id="@+id/user_settings"
            android:title="@string/user_settings_title"
            android:fragment="com.android.settings.users.UserSettings"
            android:icon="@drawable/ic_settings_multiuser"
            />

    <!-- Manage NFC payment apps 触碰付款-->
    <dashboard-tile
            android:id="@+id/nfc_payment_settings"
            android:title="@string/nfc_payment_settings_title"
            android:fragment="com.android.settings.nfc.PaymentSettings"
            android:icon="@drawable/ic_settings_nfc_payment"
            />

    <!-- Manufacturer hook -->
    <dashboard-tile
            android:id="@+id/manufacturer_settings"
            android:fragment="com.android.settings.WirelessSettings">
        <intent android:action="com.android.settings.MANUFACTURER_APPLICATION_SETTING" />
    </dashboard-tile>

</dashboard-category>

 

<!-- PERSONAL 个人-->
<dashboard-category
        android:id="@+id/personal_section"
        android:title="@string/header_category_personal" >

    <!-- Location 位置信息-->
    <dashboard-tile
            android:id="@+id/location_settings"
            android:title="@string/location_settings_title"
            android:fragment="com.android.settings.location.LocationSettings"
            android:icon="@drawable/ic_settings_location"
            />

    <!-- Security 安全-->
    <dashboard-tile
            android:id="@+id/security_settings"
            android:title="@string/security_settings_title"
            android:fragment="com.android.settings.SecuritySettings"
            android:icon="@drawable/ic_settings_security"
            />

    <!-- Account 账户-->
    <dashboard-tile
            android:id="@+id/account_settings"
            android:title="@string/account_settings_title"
            android:fragment="com.android.settings.accounts.AccountSettings"
            android:icon="@drawable/ic_settings_accounts"
            />

    <!-- Language 语言和输入法-->
    <dashboard-tile
            android:id="@+id/language_settings"
            android:title="@string/language_settings"
            android:fragment="com.android.settings.inputmethod.InputMethodAndLanguageSettings"
            android:icon="@drawable/ic_settings_language"
            />

    <!-- Backup and reset 备份和重置-->
    <dashboard-tile
            android:id="@+id/privacy_settings"
            android:title="@string/privacy_settings"
            android:fragment="com.android.settings.PrivacySettings"
            android:icon="@drawable/ic_settings_backup"
            />

</dashboard-category>

 

<!-- SYSTEM 系统-->
<dashboard-category
    android:id="@+id/system_section"
    android:title="@string/header_category_system" >

    <!-- Date & Time 日期与时间-->
    <dashboard-tile
            android:id="@+id/date_time_settings"
            android:title="@string/date_and_time_settings_title"
            android:fragment="com.android.settings.DateTimeSettings"
            android:icon="@drawable/ic_settings_date_time"
            />

    <!--Scheduled power on&off 定时开关机-->
    <dashboard-tile
            android:id="@+id/power_settings"
            android:icon="@drawable/ic_settings_schpwronoff"
            android:title="@string/schedule_power_on_off_settings_title">
        <intent android:action="com.android.settings.SCHEDULE_POWER_ON_OFF_SETTING" />
    </dashboard-tile>

    <!-- Accessibility feedback 无障碍-->
    <dashboard-tile
            android:id="@+id/accessibility_settings"
            android:title="@string/accessibility_settings"
            android:fragment="com.android.settings.accessibility.AccessibilitySettings"
            android:icon="@drawable/ic_settings_accessibility"
            />

    <!-- Print 打印-->
    <dashboard-tile
            android:id="@+id/print_settings"
            android:title="@string/print_settings"
            android:fragment="com.android.settings.print.PrintSettingsFragment"
            android:icon="@drawable/ic_settings_print"
            />

    <!-- Development 开发者选项-->
    <dashboard-tile
            android:id="@+id/development_settings"
            android:title="@string/development_settings_title"
            android:fragment="com.android.settings.DevelopmentSettings"
            android:icon="@drawable/ic_settings_development"
            />

    <!-- About Device 关于手机-->
    <dashboard-tile
            android:id="@+id/about_settings"
            android:title="@string/about_settings"
            android:fragment="com.android.settings.DeviceInfoSettings"
            android:icon="@drawable/ic_settings_about"
            />

</dashboard-category>

 

2、以上就是dashboard_categories.xml文件的列举+刷文字,在res/xml/dashboard_categories.xml;

 

 

四、来看看两个布局文件:settings_main_dashboard.xml和settings_main_prefs.xml

1、settings_main_dashboard.xml文件布局如下:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/main_content"
             android:layout_height="match_parent"
             android:layout_width="match_parent"
             android:background="@color/dashboard_background_color"
             />

2、settings_main_prefs.xml文件布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_height="match_parent"
              android:layout_width="match_parent">

    <LinearLayout
            android:orientation="vertical"
            android:layout_height="0px"
            android:layout_width="match_parent"
            android:layout_weight="1">

        <com.android.settings.widget.SwitchBar android:id="@+id/switch_bar"
                  android:layout_height="?android:attr/actionBarSize"
                  android:layout_width="match_parent"
                  android:background="@drawable/switchbar_background"
                  android:theme="?attr/switchBarTheme"
                />

        <FrameLayout
                android:id="@+id/main_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="?attr/preferenceBackgroundColor"
                />

    </LinearLayout>

    <RelativeLayout android:id="@+id/button_bar"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:layout_weight="0"
                    android:visibility="gone">

        <Button android:id="@+id/back_button"
                android:layout_width="150dip"
                android:layout_height="wrap_content"
                android:layout_margin="5dip"
                android:layout_alignParentStart="true"
                android:text="@*android:string/back_button_label"
                />

        <LinearLayout
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true">

            <Button android:id="@+id/skip_button"
                    android:layout_width="150dip"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dip"
                    android:text="@*android:string/skip_button_label"
                    android:visibility="gone"
                    />

            <Button android:id="@+id/next_button"
                    android:layout_width="150dip"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dip"
                    android:text="@*android:string/next_button_label"
                    />

        </LinearLayout>

    </RelativeLayout>

</LinearLayout>

至此,设置界面的主界面和布局文件加载的分析,可以说告一段落;下次继续分析仪表板上的每一个选项的内容

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值