導航:首頁 > 操作系統 > androidsettings修改

androidsettings修改

發布時間:2023-05-15 01:37:31

android4.1源碼中哪裡修改 Settings中Font size的默認選項

frameworks/base/core/java/android/content/res/Configuration.java文件中
public void setToDefaults() 這個方法中進行修改,

把默認字體要改為大,把fontScale值改為1.15f,全清編譯
public void setToDefaults() {
fontScale = 1.15f; //normal value is 1

⑵ 如何在系統settings里添加設置選項

目的:在通話設置菜單下,添加一dect設置菜單,裡面再添加一checkBOxPreference

來使能硬體模塊。

-------------------------

目前做的項目,需要在系統settings裡面添加一選項來使能硬體模塊,裡面涉及到的preference知識,請網上了解,這里記錄下方法。

1,settings 應用一般在 目錄:\packages\apps\Settings,我們先找到通話設置的布局位置,看看它在那個包路徑下,進入\packages\apps\Settings\res\xml,打開settings.xml文件:

Java代碼

<com.android.settings.IconPreferenceScreen

android:key="call_settings"

settings:icon="@drawable/ic_settings_call"

android:title="@string/call_settings_title">

<intent

android:action="android.intent.action.MAIN"

android:targetPackage="com.android.phone"

android:targetClass="com.android.phone.CallFeaturesSetting" />

</com.android.settings.IconPreferenceScreen>

<com.android.settings.IconPreferenceScreen

android:key="call_settings"

settings:icon="@drawable/ic_settings_call"

android:title="@string/call_settings_title">

<intent

android:action="android.intent.action.MAIN"

android:targetPackage="com.android.phone"

android:targetClass="com.android.phone.CallFeaturesSetting" />

</com.android.settings.IconPreferenceScreen>

android:targetPackage="com.android.phone"

android:targetClass="com.android.phone.CallFeaturesSetting"

targetPackage:表示包名,根據此我們可以找到通話設置的路徑。

targetClass:表示此布局文件被那個類所引用,根據此類,我們可以知道在那個文件裡面管理我們的通話設置功能。 www.55zm.com

2.根據包名,我們可以看到在\packages\apps\Phone 目錄下,進入\res\xml目錄下

找到通話布局文件:call_feature_setting.xml,根據類名,很容易找到布局文件。

裡面內容如下:

Java代碼

<PreferenceCategory android:key="button_misc_category_key"

android:title="@string/other_settings"

android:persistent="false" />

<!-- Dect settings -->

<PreferenceScreen

android:key="dect_settings"

android:title="@string/dect_mole_title"

android:summary="@string/dect_mole_title" >

<intent

android:action="android.intent.action.MAIN"

android:targetPackage="com.android.phone"

android:targetClass="com.android.phone.DectSettings" />

</PreferenceScreen>

<CheckBoxPreference

android:key="button_auto_retry_key"

android:title="@string/auto_retry_mode_title"

android:persistent="false"

android:summary="@string/auto_retry_mode_summary"/>

<PreferenceCategory android:key="button_misc_category_key"

android:title="@string/other_settings"

android:persistent="false" />

<!-- Dect settings -->

<PreferenceScreen

android:key="dect_settings"

android:title="@string/dect_mole_title"

android:summary="@string/dect_mole_title" >

<intent

android:action="android.intent.action.MAIN"

android:targetPackage="com.android.phone"

android:targetClass="com.android.phone.DectSettings" />

</PreferenceScreen>

<CheckBoxPreference

android:key="button_auto_retry_key"

android:title="@string/auto_retry_mode_title"

android:persistent="false"

android:summary="@string/auto_retry_mode_summary"/>

Dect setting 就是新添加進入的設置菜單,我們的原則盡量不大量修改,所以添加一個PreferenceScreen,新增一個類文件來管理DECt菜單選項。

android:targetPackage="com.android.phone"

android:targetClass="com.android.phone.DectSettings"

我們指明了包名,類名後,因這是個activity,所以我們需要到Phone目錄下修改

AndroidManifest.xml文件,指明啟動的activity的類名.

Java代碼

<activity android:name="CdmaCallOptions"

android:label="@string/cdma_options">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

</intent-filter>

</activity>

<!-- dect activity -->

<activity android:name="DectSettings"

android:label="@string/dect_mole_title">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

</intent-filter>

</activity>

<activity android:name="CdmaCallOptions"

android:label="@string/cdma_options">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

</intent-filter>

</activity>

<!-- dect activity -->

<activity android:name="DectSettings"

android:label="@string/dect_mole_title">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

</intent-filter>

</activity>

3.修改好後,我們必須在此activity里添加preference布局文件。

在此目錄Phone\res\xml下,新增dect_settings.xml

Java代碼

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

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"

android:title="@string/dect_mole_title">

<CheckBoxPreference

android:key="button_dect_mole_key"

android:title="@string/dect_mole_title"

android:defaultValue="true"

android:summaryOn="@string/dect_mole_start"

android:summaryOff="@string/dect_mole_stop"

/>

</PreferenceScreen>

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

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"

android:title="@string/dect_mole_title">

<CheckBoxPreference

android:key="button_dect_mole_key"

android:title="@string/dect_mole_title"

android:defaultValue="true"

android:summaryOn="@string/dect_mole_start"

android:summaryOff="@string/dect_mole_stop"

/>

</PreferenceScreen>

好了,總體布局已經完成

4.在\packages\apps\Phone\src\com\android\phone目錄下

新增DectSettings.java文件

載入布局文件:

//dect xml

addPreferencesFromResource(R.xml.dect_settings);

裡面涉及到的MidPhoneServce服務,是自己添加的,主要通過此服務的AIDL介面跟硬體打交道。想了解系統服務,請網上查找資料。

源碼如下:

Java代碼

package com.android.phone;

import android.content.DialogInterface;

import android.os.AsyncResult;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

import android.preference.CheckBoxPreference;

import android.preference.Preference;

import android.preference.PreferenceActivity;

import android.preference.PreferenceScreen;

import android.content.SharedPreferences;

import android.content.SharedPreferences.Editor;

import android.content.pm.ActivityInfo;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.os.Bundle;

import android.os.Handler;

import android.util.Log;

import android.content.Context;

import com.android.phone.R;

import android.os.IMidPhoneService;

import android.os.RemoteException;

import android.os.ServiceManager;

import android.provider.Settings;

public class DectSettings extends PreferenceActivity {

private static final String TAG = "DectSettings";

private static final String BUTTON_DECT_KEY = "button_dect_mole_key";

private CheckBoxPreference mButtonDect;

public IMidPhoneService midphoneservice = null;

@Override

protected void onCreate(Bundle icicle) {

super.onCreate(icicle);

//dect xml

addPreferencesFromResource(R.xml.dect_settings);

mButtonDect = (CheckBoxPreference)findPreference(BUTTON_DECT_KEY);

mButtonDect.setPersistent(false);

if(mButtonDect != null) {

int dect_state = Settings.System.getInt(

getContentResolver(),Settings.System.DECT_SAVED_STATE, 1);

mButtonDect.setChecked( dect_state!= 0);

Settings.System.putInt(getContentResolver(),

Settings.System.DECT_SAVED_STATE,dect_state);

Log.e(TAG,"settings:------------->" + dect_state);

}

}

@Override

public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {

if (preference == mButtonDect ) {

int dect = mButtonDect.isChecked() ? 1 : 0;

boolean state;

if(dect == 1)

state = true;

else

state = false;

try{

midphoneservice = IMidPhoneService.Stub.asInterface(ServiceManager.getService("midphone"));

Settings.System.putInt(getContentResolver(),

Settings.System.DECT_SAVED_STATE,dect);

midphoneservice.setDectEnabled(state);

Log.e(TAG,"settings:------------->" + dect);

} catch (RemoteException e) {

e.printStackTrace();

}

return true;

}

return false;

}

@Override

protected void onResume() {

super.onResume();

if (mButtonDect != null) {

mButtonDect.setChecked(Settings.System.getInt(

getContentResolver(),

閱讀全文

與androidsettings修改相關的資料

熱點內容
噴油螺桿製冷壓縮機 瀏覽:579
python員工信息登記表 瀏覽:377
高中美術pdf 瀏覽:161
java實現排列 瀏覽:513
javavector的用法 瀏覽:982
osi實現加密的三層 瀏覽:233
大眾寶來原廠中控如何安裝app 瀏覽:916
linux內核根文件系統 瀏覽:243
3d的命令面板不見了 瀏覽:526
武漢理工大學伺服器ip地址 瀏覽:149
亞馬遜雲伺服器登錄 瀏覽:525
安卓手機如何進行文件處理 瀏覽:71
mysql執行系統命令 瀏覽:930
php支持curlhttps 瀏覽:143
新預演算法責任 瀏覽:444
伺服器如何處理5萬人同時在線 瀏覽:251
哈夫曼編碼數據壓縮 瀏覽:426
鎖定伺服器是什麼意思 瀏覽:385
場景檢測演算法 瀏覽:617
解壓手機軟體觸屏 瀏覽:350