如下圖,找到對應的source for Android sdk項,選中然後下載:
㈡ 怎樣在源代碼中修改android系統的屏幕默認
1、首先解決【設置】界面默認顯示【開發者選項】的問題
查看源代碼:packages/apps/Settings/src/com/android/settings/SettingsActivity.java
在updateTilesList(Listtarget)方法中,可以找到【開發者選項】相關的代碼:
else if (id == R.id.development_settings) {Log.d(LOG_TAG, =================oyp K=+showDev);if (!showDev || um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) {removeTile = true;}}
其中showDev變數定義在該方法最開始處
因此要想特定客戶直接顯示【開發者選項】,則將showDev的值改變即可,代碼如下:
即在初始化showDev變數之前,將DevelopmentSettings.PREF_SHOW的值設置為true,那麼showDev也會是true。這樣【開發者選項】就會默認打開。那個判斷是J5客戶的方法在/frameworks/base/core/java/android/os/SystemProperties.java中定義
因為這個添加的代碼是在SecuritySettings的createPreferenceHierarchy()方法中,也就是說要進入到該Activity才生效。這樣明顯沒達到目的。
因此要和設置【USB調試】一樣,在一個接收開機廣播的廣播接收者中將Settings.Global.INSTALL_NON_MARKET_APPS設置為1。
4、找Settings裡面定義的一個接收開機廣播的廣播接收者,在AndroidManifest.xml中找到一個,當然你也可以自己定義一個這樣的廣播接收者。
<!-- Restore Rotation Receiver --><receiver android:name="com.mediatek.settings.RestoreRotationReceiver"><intent-filter></action></action></intent-filter></receiver>
因此在packages/apps/Settings/src/com/mediatek/settings/RestoreRotationReceiver.java的onReceive(Context context, Intent intent)方法中加入以下代碼:
而一開始添加的代碼可以注釋掉了。通過git diff可以看出來
diff --git a/packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java b/packages/apps/Settings/src/com/android/settings/Develindex 0a987df..503270a 100755--- a/packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java+++ b/packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java@@ -508,15 +508,9 @@ public class DevelopmentSettings extends Context context = getActivity();final ContentResolver cr = context.getContentResolver();mHaveDebugSettings = false;-/// M: CR ALPS00244115. Lock and unlock screen, the USB debugging is unchecked.boolean isChecked = (mAdbDialog != null && mAdbDialog.isShowing()) ? true :(Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) != 0);- //added by ouyang 2015-11-10 set mEnableAdb=true if model is J5- if (android.os.SystemProperties.isJ5Version()) {- isChecked=true;- }- //added by ouyang 2015-11-10 enpdateSwitchPreference(mEnableAdb, isChecked);/// M: update usb preference againmExt.customUSBPreference(mEnableAdb);
這樣改為後,編譯,刷機後,插上USB數據線就可以開始進行adb調試了,而且可以直接安裝未知來源的apk了。
㈢ android toast樣式源碼在哪個文件夾下
oast toast= Toast.makeText(getApplicationContext(), "Toast Here", Toast.LENGTH_SHORT); //放在左上角。如果你想往右邊移動,將第二個參數設為>0;往下移動,增大第三個參數;後兩個參數都只得像素toast.setGravity(Gravity.TOP|Gravity.LE
㈣ android開發,查看android源碼的時候,裡面引用了一些布局文件,這些布局文件的位置在哪裡
你可以按住ctrl,用滑鼠左鍵點擊代碼中布局文件的名稱,就會直接跳轉到該布局文件
㈤ 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
㈥ Android源代碼 請問,1,從網上下載的android源碼應該放在SDK哪個目錄下面,以什麼樣的格式
不知道你要把源碼放在SDk中 幹啥用,還有下載好源代碼的SDK啥意思,windows下下載不了源代碼,要在windows上裝個cygwin或者在虛擬機里裝個ubuntu
㈦ 安卓APP反編譯後的程序源代碼在哪裡
assets是html文件,lib是jar,res是資源文件。AndroidManifest是配置文件,源碼在smali和original裡面
㈧ 安卓應用的代碼和ui等數據一般保存在什麼文件夾里怎麼打開
這個數據一般隨著刪除應用或者刷機就沒有了。數據位置是這里,能訪問的前提是你已經root了,使用re管理器來到這個文件夾的位置:data/data/com.handsgo.jiakao.android
這裡面有所有該應用的數據,你將他們復制出來,格機好了以後安裝駕考寶典,然後復制回去應該就可以了。我自己也正好裝了這款應用。
望採納,謝謝。
㈨ 從源碼中淺析Android中怎麼利用attrs和styles定義控制項
1.attrs.xml:
我們知道Android的源碼中有attrs.xml這個文件,這個文件實際上定義了所有的控制項的屬性,就是我們在布局文件中設置的各類屬性
你可以找到attrs.xml這個文件,打開它,全選,右鍵->Show In->OutLine。可以看到整個文件的解構
我們大概可以看出裡面是Android中的各種屬性的聲明,比如textStyle這個屬性是這樣定義的:
Java代碼
<!-- Default text typeface style. -->
<attr name="textStyle">
<flag name="normal" value="0" />
<flag name="bold" value="1" />
<flag name="italic" value="2" />
</attr>
那麼現在你知道,我們在寫android:textStyle的時候為什麼會出現normal,bold和italic這3個東西了吧,就是定義在這個地方。
再看看textColor:
Java代碼
<!-- Color of text (usually same as colorForeground). -->
<attr name="textColor" format="reference|color" />
format的意思是說:這個textColor可以以兩種方式設置,要麼是關聯一個值,要麼是直接設置一個顏色的RGB值,這個不難理解,因為我們可以平時也這樣做過。
也就是說我們平時在布局文件中所使用的各類控制項的屬性都定義在這裡面,那麼這個文件,除了定義這些屬性外還定義了各種具體的組件,比如TextView,Button,SeekBar等所具有的各種特有的屬性
比如SeekBar:
Java代碼
<declare-styleable name="SeekBar">
<!-- Draws the thumb on a seekbar. -->
<attr name="thumb" format="reference" />
<!-- An offset for the thumb that allows it to extend out of the range of the track. -->
<attr name="thumbOffset" format="dimension" />
</declare-styleable>
也許你會問SeekBar的background,等屬性怎麼沒有看到?這是因為Android中幾乎所有的組件都是從View中繼承下來的,SeekBar自然也不例外,而background這個屬性幾乎每個控制項都有,因此被定義到了View中,你可以在declare-styleable:View中找到它。
總結下,也就是說attrs.xml這個文件定義了布局文件中的各種屬性attr:***,以及每種控制項特有的屬性declare-styleable:***
2.styles.xml:
剛才的attrs.xml定義的是組件的屬性,現在要說的style則是針對這些屬性所設置的值,一些默認的值。
這個是SeekBar的樣式,我們可以看到,這裡面設置了一個SeekBar的默認的樣式,即為attrs.xml文件中的各種屬性設置初始值
Java代碼
<style name="Widget.SeekBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
<item name="android:thumb">@android:drawable/seek_thumb</item>
<item name="android:thumbOffset">8dip</item>
<item name="android:focusable">true</item>
</style>
這個是Button的樣式:
Java代碼
<style name="Widget.Button">
<item name="android:background">@android:drawable/btn_default</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
<item name="android:textColor">@android:color/primary_text_light</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
有了屬性和值,但是這些東西是如何關聯到一起的呢?它們如何被android的framework層所識別呢?
3.組件的源碼
我們看下TextView的源碼:
Java代碼
public TextView(Context context) {
this(context, null);
}//這個構造器用來給用戶調用,比如new TextView(this);
public TextView(Context context,
AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.textViewStyle);
}
public TextView(Context context,
AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);//為用戶自定義的TextView設置默認的style
mText = "";
//設置畫筆
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.density = getResources().getDisplayMetrics().density;
mTextPaint.setCompatibilityScaling(
getResources().getCompatibilityInfo().applicationScale);
mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mHighlightPaint.setCompatibilityScaling(
getResources().getCompatibilityInfo().applicationScale);
mMovement = getDefaultMovementMethod();
mTransformation = null;
//attrs中包含了這個TextView控制項在布局文件中定義的屬性,比如android:background,android:layout_width等
//com.android.internal.R.styleable.TextView中包含了TextView中的針對attrs中的屬性的默認的值
//也就是說這個地方能夠將布局文件中設置的屬性獲取出來,保存到一個TypeArray中,為這個控制項初始化各個屬性
TypedArray a =
context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.TextView, defStyle, 0);
int textColorHighlight = 0;
ColorStateList textColor = null;
ColorStateList textColorHint = null;
ColorStateList textColorLink = null;
int textSize = 15;
int typefaceIndex = -1;
int styleIndex = -1;
/*
* Look the appearance up without checking first if it exists because
* almost every TextView has one and it greatly simplifies the logic
* to be able to parse the appearance first and then let specific tags
* for this View override it.
*/
TypedArray appearance = null;
//TextView_textAppearance不太了解為什麼要這樣做?難道是為了設置TextView的一些默認的屬性?
int ap = a.getResourceId(com.android.internal.R.styleable.TextView_textAppearance, -1);
if (ap != -1) {
appearance = context.obtainStyledAttributes(ap,
com.android.internal.R.styleable.
TextAppearance);
}
if (appearance != null) {
int n = appearance.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = appearance.getIndex(i);
switch (attr) {
case com.android.internal.R.styleable.TextAppearance_textColorHighlight:
textColorHighlight = appearance.getColor(attr, textColorHighlight);
break;
case com.android.internal.R.styleable.TextAppearance_textColor:
textColor = appearance.getColorStateList(attr);
break;
case com.android.internal.R.styleable.TextAppearance_textColorHint:
textColorHint = appearance.getColorStateList(attr);
break;
case com.android.internal.R.styleable.TextAppearance_textColorLink:
textColorLink = appearance.getColorStateList(attr);
break;
case com.android.internal.R.styleable.TextAppearance_textSize:
textSize = appearance.getDimensionPixelSize(attr, textSize);
break;
case com.android.internal.R.styleable.TextAppearance_typeface:
typefaceIndex = appearance.getInt(attr, -1);
break;
case com.android.internal.R.styleable.TextAppearance_textStyle:
styleIndex = appearance.getInt(attr, -1);
break;
}
}
appearance.recycle();
}
//各類屬性
boolean editable = getDefaultEditable();
CharSequence inputMethod = null;
int numeric = 0;
CharSequence digits = null;
boolean phone = false;
boolean autotext = false;
int autocap = -1;
int buffertype = 0;
boolean selectallonfocus = false;
Drawable drawableLeft = null, drawableTop = null, drawableRight = null,
drawableBottom = null;
int drawablePadding = 0;
int ellipsize = -1;
boolean singleLine = false;
int maxlength = -1;
CharSequence text = "";
CharSequence hint = null;
int shadowcolor = 0;
float dx = 0, dy = 0, r = 0;
boolean password = false;
int inputType = EditorInfo.TYPE_NULL;
int n = a.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = a.getIndex(i);
//通過switch語句將用戶設置的,以及默認的屬性讀取出來並初始化
switch (attr) {
case com.android.internal.R.styleable.TextView_editable:
editable = a.getBoolean(attr, editable);
break;
case com.android.internal.R.styleable.TextView_inputMethod:
inputMethod = a.getText(attr);
break;
case com.android.internal.R.styleable.TextView_numeric:
numeric = a.getInt(attr, numeric);
break;
//更多的case語句...
case com.android.internal.R.styleable.TextView_textSize:
textSize = a.getDimensionPixelSize(attr, textSize);//設置當前用戶所設置的字體大小
break;
case com.android.internal.R.styleable.TextView_typeface:
typefaceIndex = a.getInt(attr, typefaceIndex);
break;
//更多的case語句...
}
通過上面的代碼大概可以知道,每個組件基本都有3個構造器,其中只傳遞一個Context上下文的那個構造器一般用來在java代碼中實例化使用。
比如你可以
Java代碼
TextView tv = new TextView(context);
來實例化一個組件。
最終調用的是第3個構造器
Java代碼
public TextView(Context context,
AttributeSet attrs,
int defStyle)
在這個構造器中為你設置了默認的屬性attrs和值styles。關鍵不在這里,而是後面通過使用下面的代碼
Java代碼
TypedArray a =
context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.TextView, defStyle, 0);
來將屬性和值獲取出來,放到一個TypeArray中,然後再利用一個switch語句將裡面的值取出來。再利用這些值來初始化各個屬性。這個View最終利用這些屬性將這個控制項繪制出來。
如果你在布局文件中定義的一個View的話,那麼你定義的值,會被傳遞給構造器中的attrs和styles。也是利用同樣的方式來獲取出你定義的值,並根據你定義的值來繪制你想要的控制項。
再比如其實Button和EditText都是繼承自TextView。看上去兩個控制項似乎差異很大,其實不然。Button的源碼其實相比TextView變化的只是style而已:
㈩ android怎麼設置app使用的默認字體庫
Android系統自帶有對字體的設置,這些設置是對字體的顯示方式的設置,比如加粗,傾斜,下劃線,字型大小等,但是對於字體本身,比如設置為楷體,隸書等貌似沒有。Android系統只有一種默認的,如果需要修改字體,或者引用自己喜歡的字體,那麼就需要自己設置或修改。
修改系統的字體可以下載修改字體的app即可,但是如果是對於開發者想在自己的app中使用具有自己個性的文字,可以按下面介紹的方法做(這里只是其中一種方法,相信,應該還有很多方法的)
·將自定義的字體所在的ttf文件到工程assets/fonts/目錄下面
一般字體的格式為ttf的。在C:\WINDOWS\Fonts目錄下有windows系統提供的字體,可以使用。也可以自己通過coreldraw+fontcreator軟體自己製作字體
·在源碼中進行如下修改:
TextView tv = (TextView)findViewById(R.id.c12_custom);1
//從assert中獲取有資源,獲得app的assert,採用getAserts(),通過給出在assert/下面的相對路徑。在實際使用中,字體庫可能存在於SD卡上,可以採用createFromFile()來替代createFromAsset。
Typeface face = Typeface.createFromAsset ( getAssets() , 「fonts/timesi.ttf」 );
tv.setTypeface (face);12
設置字體不能直接在XML文件中進行,需要通過源碼來完成。
通過這兩步就可以對TextView對象tv的字體進行了修改,改成自己定義的字體timesi.ttf
Android並非和所有的TTF字體都能兼容,尤其在中文特殊字體的支持會存在問題,對於不兼容的字體,Android不出報錯,只是無法正常顯示。
一些注意
字型檔一般會很大,因為要將包括很多的字元集,使用其他的字型檔,這樣就會增大程序的體積。可以使用FontCreator軟體對字型檔進行裁剪,使其體積變小。如果字型檔比較大,可以考慮放在sdcard上,使用createFromFile來獲得Typeface對象
有些字型檔可能並不會包括我們需要的字元,比如為了節省字型檔的體積,將中文字元取消,這樣如果想使用這個字型檔顯示中文的話,肯定是不成功的。
這里再對程序中出現的源碼進行解釋。
修改字體就是調用setTypeface方法。這個方法的參數是一個Typeface類對象
Typeface是字體類
這個類比較簡單,這里列出它的成員方法(這些方法都是靜態方法,返回Typeface對象,可以直接作為setTypeface的參數):
·static Typeface create(Typeface family, int style) //靜態方法,參數一為字體類型這里是Typeface的靜態定義,如宋體,參數二風格,如粗體,斜體
·static Typeface create(String familyName, int style) //靜態方法,參數一為字體名的字元串,參數二為風格同上,這里我們推薦使用上面的方法。
·static Typeface createFromAsset(AssetManager mgr, String path) //靜態方法,參數一為AssetManager對象,主要用於從APK的assets文件夾中取出字體,參數二為相對於Android工程下的assets文件夾中的外掛字體文件的路徑。
·static Typeface createFromFile(File path) //靜態方法,從文件系統構造一個字體,這里參數可以是sdcard中的某個字體文件
·static Typeface createFromFile(String path) //靜態方法,從指定路徑中構造字體
·static Typeface defaultFromStyle(int style) //靜態方法,返回默認的字體風格
本類的常量靜態定義,首先為字體類型名稱
Typeface DEFAULT
Typeface DEFAULT_BOLD
Typeface MONOSPACE
Typeface SANS_SERIF
Typeface SERIF
字體風格名稱
int BOLD
int BOLD_ITALIC
int ITALIC
int NORMAL
這些變數都可以通過名稱知道其意思