在整个Settings里面activityPreference和listPreference这类的偏好设置用的特别多所以相应的xml文件也相当的多
先从Settings的主页面SettingsActivity.java说起吧
在SettingsActivity.java的onCreate里面会进行判断导入哪个布局:
setContentView(mIsShowingDashboard ?
R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
这两个布局是一级页面和二级页面,一级页面也就是主页面,点击主页面里的选项就会进入二级页面
两个布局里都有id为main_content的FrameLayout控件
一级页面的所有东西都是在上面显示的,像wifi啊,蓝牙啊等等
而显示的wifi,蓝牙什么的就是通过解析dashboard_categories.xml得出来的
private void buildDashboardCategories(List<DashboardCategory> categories) {
categories.clear();
loadCategoriesFromResource(R.xml.dashboard_categories, categories);
updateTilesList(categories);
}
dashboard_categories.xml:
<dashboard-categories
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- WIRELESS and NETWORKS -->
<dashboard-category
android:id="@+id/wireless_section"
android:title="@string/header_category_wireless_networks" >
<!-- Wifi -->
<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 -->
<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>
<!-- 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>
</dashboard-categories>
如果你想要去掉某一个就找到 updateTilesList(List<DashboardCategory> target)这个方法
在它的for循环里加一个对应的
else if (id == R.id.battery_settings) {
removeTile = true;
}
这样就可以了.解析的时候还涉及到DashboardSummary.java等一些类,具体不详说
然后点击某个选项的时候通过switchToFragment(String fragmentName, Bundle args, boolean validate,
boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
if (validate && !isValidFragment(fragmentName))
boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
if (validate && !isValidFragment(fragmentName))
这个类判断打开那个fragment