android setting.apk 界面中删除某个菜单选项

那么有哪些多余的东西呢?比如在主菜单中的“设置/呼叫”,“设置/辅助”功能选项,“设置/关于手机/XX”功能选项,“设置/显示/XX”功能选项。本人的手机是HTC g6,android 2.2 内核2.6.32.17。下面所截的图是我手机上的图,我们公司用的是android 2.3,现在在弄4.0版本。相对与我手机的2.2,投影机的2.3版本差别不大。
 
  
 
                                      界面修改图
    那么怎么去掉这些选项呢?首先还得看代码,找到代码是关键。
 
  
    代码一般在package/apps/Settings/下,看上图的文件与文件夹,我们只需关心res 与 src 这两个文件夹里面的内容,前者是资源文件目录,后者是源代码也就是java源代码的目录。 先看下主界面是如何出现的,在src/com/android/settings/中找到Settings.java,可以看到程序就那么几行。
 
  
 
  

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);         addPreferencesFromResource(R.xml.settings);         int activePhoneType = TelephonyManager.getDefault().getPhoneType();

......

就是这句代码了,addPreferencesFromResource(R.xml.settings);它调用的界面布局文件R.xml.settings。好吧,继续找。R可以认为它是res文件夹,它是自动生成的,不管它。在res/xml/中我们发现settings.xml,代码如下。它与设置主界面一一对应。
 
  

xml version="1.0" encoding="utf-8"?>

    xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"     android:title="@string/settings_label"     android:key="parent">

                    android:title="@string/radio_controls_title"             settings:icon="@drawable/ic_settings_wireless">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.WirelessSettings" />                

                    settings:icon="@drawable/ic_settings_sound"             android:title="@string/sound_settings_title">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.SoundSettings" />        

       

                    settings:icon="@drawable/ic_settings_display"             android:title="@string/display_settings_title">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.DisplaySettings" />           

  

       

                    settings:icon="@drawable/ic_settings_security"             android:title="@string/security_settings_title"             android:key="security_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.SecuritySettings" />        

       

                    settings:icon="@drawable/ic_settings_applications"             android:title="@string/applications_settings"             android:key="applications_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.ApplicationSettings" />        

       

                    settings:icon="@drawable/ic_settings_sync"             android:title="@string/sync_settings"             android:key="sync_settings">             android:action="android.settings.SYNC_SETTINGS" />        

       

                    settings:icon="@drawable/ic_settings_privacy"             android:title="@string/privacy_settings"             android:key="privacy_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.PrivacySettings" />        

       

                    settings:icon="@drawable/ic_settings_storage"             android:title="@string/storage_settings">             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.deviceinfo.Memory" />        

       

                    settings:icon="@drawable/ic_settings_language"             android:title="@string/language_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.LanguageSettings" />        

       

                    settings:icon="@drawable/ic_settings_speech"             android:title="@string/voice_input_output_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.VoiceInputOutputSettings" />        

               

                    android:key="dock_settings"             settings:icon="@drawable/ic_settings_dock"             android:title="@string/dock_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.DockSettings" />        

       

                    settings:icon="@drawable/ic_settings_date_time"             android:title="@string/date_and_time_settings_title">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.DateTimeSettings" />        

 

       

                    settings:icon="@drawable/ic_settings_about"             android:title="@string/about_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.DeviceInfoSettings" />        

    boss叫我去掉通话。在下面代码前后加上 注释掉,编译,烧写,测试,没问题,通话去掉了。
 
  

    辅助功能也按同样方法去掉。
    在关于手机中去掉一些选项,此时我们仅仅需要去掉子菜单里的选项,所以要有些区别。在Settings.xml中我们看到最后部分。
 
  
 
  

                    settings:icon="@drawable/ic_settings_about"             android:title="@string/about_settings">                             android:action="android.intent.action.MAIN"                 android:targetPackage="com.android.settings"                 android:targetClass="com.android.settings.DeviceInfoSettings" />        


他与intent 机制有关,可以把它当做一个任务,如果只是修改界面娱乐不需暂且不管,看到android:targetClass="com.android.settings.DeviceInfoSettings"这句,把它当做调用语句,调用com.android.settings.DeviceInfoSettings这个文件里的代码。找到\src\com\android\settings\eviceInfoSettings.java中的看看代码中有什么东西。同样可以看到有如下:
又有类似的方法,addPreferencesFromResource(R.xml.device_info_settings);界面布局文件也跟进看看。
 
  
 
  

    @Override     protected void onCreate(Bundle icicle) {         super.onCreate(icicle);

        addPreferencesFromResource(R.xml.device_info_settings);

......

可以发现该界面布局是静态布局方式,用到与持久化数据有关的Preference,不过不管它,直接加注释同样去掉即可。
 
  
 
  

xml version="1.0" encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"         android:title="@string/about_settings">

                android:key="system_update_settings"                 android:title="@string/system_update_settings_list_item_title"                 android:summary="@string/system_update_settings_list_item_summary">             android:action="android.settings.SYSTEM_UPDATE_SETTINGS" />                               ......

然后试着去掉“设置/显示/中的自动旋转屏幕”,同样方法加注释,不过编译,烧写,运行后出现“...很抱歉,应用程序意外停止,请重试..."类似的字眼,很显然代码注释后有关联的代码没去掉,也就是没去干净。查看java源码。android:targetClass="com.android.settings.DisplaySettings" 去掉相关代码如下所示。
 
 
  

@@ -74,8 +74,8 @@ public class DisplaySettings extends PreferenceActivity implements            mAnimations = (ListPreference) findPreference(KEY_ANIMATIONS);          mAnimations.setOnPreferenceChangeListener(this); -        mAccelerometer = (CheckBoxPreference)findPreference(KEY_ACCELEROMETER); -        mAccelerometer.setPersistent(false); +        //mAccelerometer = (CheckBoxPreference)findPreference(KEY_ACCELEROMETER); +        //mAccelerometer.setPersistent(false);          HdmiState = new File("/sys/class/hdmi/hdmi-0/state");            ListPreference screenTimeoutPreference = @@ -174,9 +174,9 @@ public class DisplaySettings extends PreferenceActivity implements          }          mAnimations.setValueIndex(idx);          updateAnimationsSummary(mAnimations.getValue()); -        mAccelerometer.setChecked(Settings.System.getInt( -                getContentResolver(), -                Settings.System.ACCELEROMETER_ROTATION, 0) != 0); +        //mAccelerometer.setChecked(Settings.System.getInt( +                //getContentResolver(), +                //Settings.System.ACCELEROMETER_ROTATION, 0) != 0);      }

这样修改便能通过了,不会出现错误了。其实可以用adb调试查看代码出错的地方,非常快速定位错误点。每个人出现问题的方面不同,用adb调试是非常好的选择。
 
  
这篇文章是转载的,可以解决大部分我对settings的设置要求了,推荐!
 
 

你可能感兴趣的:(A10_android4.0)