关闭

android Settings 分析

428人阅读 评论(0) 收藏 举报
分类:

可以模仿Settings其他菜单项加入自己想要的一级或二级子菜单项。

比如,在菜单Settings里加入一级和二级Usb Mode Settings菜单项 (以Android4.4 KK为例)

一. 加入一级子菜单项Usb Mode Settings, 加在About phone后面

1. packages/apps/Settings/AndroidManifest.xml
        <activity Android:name="Settings$DeviceInfoSettingsActivity"
                android:theme="@style/Theme.Holo.DialogWhenLarge"
                android:label="@string/device_info_settings"
                android:taskAffinity="com.android.settings"
                android:parentActivityName="Settings">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.settings.DEVICE_INFO_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />db
                <category android:name="android.intent.category.VOICE_LAUNCH" />
            </intent-filter>
            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                android:value="com.android.settings.DeviceInfoSettings" />
            <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
                android:resource="@id/about_settings" />
        </activity>

        <activity android:name="Settings$UsbModeSettingsActivity"
                android:theme="@style/Theme.SubSettingsDialogWhenLarge"
                android:label="@string/usb_mode_settings"
                android:taskAffinity="com.android.settings"
                android:parentActivityName="Settings">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.settings.USB_MODE_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                android:value="com.android.settings.UsbModeSettings" />
            <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
                android:resource="@id/usb_mode_settings" />
        </activity>


2. packages/apps/Settings/res/xml/settings_headers.xml 
        <!-- 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"
                />
                
        <!-- Usb Mode -->
        <dashboard-tile
                android:id="@+id/usb_mode_settings"
                android:title="@string/usb_mode_settings"
                android:fragment="com.android.settings.UsbModeSettings"
                android:icon="@drawable/ic_settings_about"
                />


 Lollipop
packages\apps\Settings\res\xml\dashboard_categories.xml        
        <!-- Usb Mode -->
        <dashboard-tile
                android:id="@+id/usb_mode_settings"
                android:title="@string/usb_mode_settings"
                android:fragment="com.android.settings.UsbModeSettings"
                android:icon="@drawable/ic_settings_about"
                />
3. packages\apps\Settings\src\com\android\settings\Settings.Java
     public static class DeviceInfoSettingsActivity extends SettingsActivity { /* empty */ }
+    public static class UsbModeSettingsActivity extends SettingsActivity { /* empty */ }
     public static class ApplicationSettingsActivity extends SettingsActivity { /* empty */ }

4. packages/apps/Settings/src/com/android/settings/Settings.java
            DeviceInfoSettings.class.getName(),
+            UsbModeSettings.class.getName(),
             ManageApplications.class.getName(),

Lollipop
packages\apps\Settings\src\com\android\settings\SettingsActivity.java
            DeviceInfoSettings.class.getName(),
+            UsbModeSettings.class.getName(),
            ManageApplications.class.getName(),

 

5. packages/apps/Settings/res/values/strings.xml
增加新字符串

新增部分
6. packages/apps/Settings/res/drawable/
添加图标

7. 模仿packages/apps/Settings/res/xml/device_info_settings.xml新加一layout文件
packages/apps/Settings/res/xml/usb_mode_settings.xml
      android:title="@string/about_settings">        
        <!-- Device status - launches activity -->
        <PreferenceScreen android:key="status_info"
                android:title="@string/device_status" 
                android:summary="@string/device_status_summary">
            <intent android:action="android.intent.action.MAIN"
                    android:targetPackage="com.android.settings"
                    android:targetClass="com.android.settings.deviceinfo.Status" />
        </PreferenceScreen>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:title="@string/usb_mode_settings">
    <PreferenceCategory
            android:title="@string/usb_connection_category" />
    <CheckBoxPreference
        android:key="usb_mtp"
        android:title="@string/usb_mtp_title"
        android:summary="@string/usb_mtp_summary"
        />
    <CheckBoxPreference
        android:key="usb_mass_storage"
        android:title="@string/usb_ptp_title"
        android:summary="@string/usb_ptp_summary"
        />
</PreferenceScreen>

8. 模仿packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java新加一代码实现
packages/apps/Settings/src/com/android/settings/UsbModeSettings.java

 

二. 加入一级子菜单项Usb Mode Settings, 加在Developer options下面, 在"Desktop backup password"后面

1.packages/apps/Settings/AndroidManifest.xml
        <activity android:name="SetFullBackupPassword"
                android:theme="@style/Theme.SubSettingsDialogWhenLarge"
                android:exported="false">
        </activity>

        <activity android:name="UsbModeSettings"
                android:theme="@style/Theme.SubSettingsDialogWhenLarge"
                android:exported="false">
        </activity>


2. packages/apps/Settings/res/xml/development_prefs.xml
    <PreferenceScreen
            android:key="local_backup_password"
            android:title="@string/local_backup_password_title"
            android:summary="@string/local_backup_password_summary_none"
            android:persistent="false" >
        <intent
                android:action="android.settings.privacy.SET_FULL_BACKUP_PASSWORD"
                android:targetPackage="com.android.settings"
                android:targetClass="com.android.settings.SetFullBackupPassword" />
    </PreferenceScreen>

    <PreferenceScreen
            android:key="usb_mode"
            android:title="@string/usb_mode_settings"
            android:summary="@string/usb_mode_settings_summary"
        <intent
                android:action="android.intent.action.MAIN"
                android:targetPackage="com.android.settings"
                android:targetClass="com.android.settings.UsbModeSettings" />
    </PreferenceScreen>

3. /packages/apps/Settings/res/values/strings.xml
+    <string name="usb_mode_settings">USB mode settings</string>
......


4. 新加文件

      res/layout/usb_mode_settings.xml

     packages/apps/Settings/res/drawable/ 图标
 

    src/com/android/settings/UsbModeSettings.java

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    文章分类
    文章存档
    最新评论