实现项是Activity的话比较简单,如上述HardKey.java,此类文件直接继承的是Activity,添加比较简单
(1)、在清单文件中添加如下内容
<activity android:name="HardKey"
android:label="@string/hardkey_switch"
android:icon="@drawable/a2_zuo_you_jiaohuan_2"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="com.android.settings.HARDKEY" />
<action android:name="android.settings.HARDKEY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<intent-filter android:priority="9">//在category中的物理位置(按优先级排序时用到,并不是指第9个位置,数越大优先级越大越靠前)
<action android:name="com.android.settings.action.SETTINGS" />//指定此项在settings中显示
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.device" />//指定此项显示在device这一category中
<meta-data android:name="com.android.settings.ACTIVITY_ACTION" //ACTIVITY_ACTION表明 value指向的类是Activity
android:value="com.android.settings.HardKey" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
(2)、自己实现HardKey这个Activity,其中是按键交换功能逻辑的实现
2、一级菜单项的实现是fragment
(1)、在清单文件中添加如下内容
<activity android:name="Settings$FlashSettingsActivity" //注意此处,FlashSettingsActivity是Settings的内部类,后面会解释
android:label="@string/flash_control_title"
android:icon="@drawable/a2_hu_xi_deng_2"
android:taskAffinity="">
<intent-filter android:priority="1">
<action android:name="com.android.settings.FLASH_SETTING" />
<action android:name="android.settings.FLASH_SETTING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<intent-filter android:priority="9">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.device" />
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"//FRAGMENT_CLASS 表明value指定的类是fragment
android:value="com.android.settings.FlashSettings" /> //FlashSettings实现类
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
(2)、自己实现FlashSettings 这个fragment
### (3)、在Settings.java中添加
public static class FlashSettingsActivity extends SettingsActivity { /* empty */ }