導航:首頁 > 操作系統 > 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修改相關的資料

熱點內容
用銀行家演算法拒絕死鎖的例題 瀏覽:670
洗盤選股指標源碼 瀏覽:705
百度雲盤下載的壓縮包怎麼解壓 瀏覽:737
加密類型是TKIP被我弄掉了 瀏覽:234
貝刻智能手環app如何下載 瀏覽:838
公司電腦上的加密文件解密 瀏覽:462
伺服器怎麼配置資料庫 瀏覽:889
壓縮機和製冷劑 瀏覽:182
樹莓派手機版編程 瀏覽:926
谷歌編程挑戰賽時間安排 瀏覽:438
自動學習機源碼 瀏覽:938
明日之後星曳鎮是什麼伺服器 瀏覽:474
編程學有年齡限制嗎 瀏覽:571
工程可靠度pdf 瀏覽:900
包子解壓玩具會爆嗎 瀏覽:143
資治通鑒柏楊版pdf 瀏覽:852
跆拳道pdf 瀏覽:205
程序員畢設可以攻哪個方向 瀏覽:427
毛絨玩具怎麼壓縮 瀏覽:378
拖拉式編程教學視頻 瀏覽:793