安卓源碼默認的樣式在哪個文件
android的源碼首先需要你從Android SDK Manager裡面下載,然後在你的sdk中才看得到。
如下圖,找到對應的source for Android sdk項,選中然後下載:
⑵ 如何查看安卓apk程序的源代碼
將apk文件拷貝至sdcard上。
命令順序如下:
進入Android sdk文件夾/tools目錄下
輸入adb shell
輸入su
輸入cd data
輸入cd app
這時就可以看到你安裝的所有的apk文件。輸入cp 空格 對應的apk 空格 /sdcard/
這樣就將apk文件拷貝出來了。
將apk文件後綴直接變成rar格式,可以看到熟悉的目錄結構了,
其中xml文件打開後都是二進制的,無法查看。
這時就用到了一個android4me的AXMLPrinter2工具。(請自行網路搜索)
輸入以下命令,將xml文件解析出來
java -jar AXMLPrinter2.jar showtimes_list.xml
此命令是在命令行中查看此showtimes_list.xml
將showtimes_list.xml生成xml文件,則輸入以下命令:
java -jar AXMLPrinter2.jar showtimes_list.xml > h.xml
目前進行到這一步,只能看到xml文件的內容,其工程中的java源文件還是看不到,看目錄結構下有一個classes.dex文件,我們需要將dex文件變為jar文件。
這里用到了另一個工具dex2jar。(自行搜索下載)
在Windows下解壓之後的目錄如下圖所示:
在命令行中,進入到此目錄下:
在Windows下,輸入以下命令:
dex2jar.bat c:\classes.dex
運行完之後,在C盤會多一個classes.dex.dex2jar.jar文件,此文件就是我們需要的jar文件。
利用jd-gui,將jar文件反向工程為java代碼。(請自行搜索下載)
它分為Windows、Linux、和max三個版本,這里我下載的是Windows版本的。
解壓之後,雙擊運行exe文件,選擇classes.dex.dex2jar.jar文件,相應的jar文件中的Java文件就被反向工程顯示出來了!
⑶ 從源碼中淺析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源碼中有關控制項的布局文件在哪個文件夾里
這些是android源碼中的一些代碼,請問下,誰知道這個參數各是什麼意思??
⑸ androidapp源代碼在哪個文件夾
在src文件夾里邊。res文件夾是布局的。bin里邊是App的安裝包文件夾。
⑹ eclipse中android系統源碼在哪個文件夾
在Eclipse中查看Android源代碼 1.需要下載一個對應的android sdk,下完了後找到souce目錄,將其中所有的內容拷貝到eclipse所用的sdk下的source目錄下,如果沒有這個目錄則新建一個。 2.在eclipse中打開一個android的類文件,會出現如下圖所示提示: 點擊其中的「Change Attached Source"按鈕,在彈出的對話框中選擇「External Floder",選擇前面復制文件所在的source文件夾。 3.重啟eclipse,一切ok了,可以直接查看android的源代碼,如下圖所示。
⑺ 安卓應用的代碼和ui等數據一般保存在什麼文件夾里怎麼打開
額。。。樓上………data保存的只是應用深層數據。安卓源代碼是找不到,找到也不可能改,安卓源代碼googl不可能隨便讓你改的,改了就不是安卓了。但是一些源數據、源文件是保存在根目錄的system
文件夾下的,有能力的話可以進行修改、替換,還有system/
build.prop文件里有一些安卓數據,可以進行修改。你可以用re文件管理器打開進行修改(最高別亂改,改錯了會變磚),前提要root
⑻ android系統中,有關框架層的代碼應該在以下哪個目錄中
Google提供的Android包含了原始Android的目標機代碼,主機編譯工具、模擬環境,下載的代碼包經過解壓後(這里是Android2.2的源碼包),源代碼的第一層目錄結構如下:
|-- Makefile
|-- bionic (bionic C庫)
|-- bootable (啟動引導相關代碼)
|-- build (存放系統編譯規則及generic等基礎開發包配置)
|-- cts (Android兼容性測試套件標准)
|-- dalvik (dalvik JAVA虛擬機)
|-- development (應用程序開發相關)
|-- external (android使用的一些開源的模組)
|-- frameworks (核心框架——java及C++語言)
|-- hardware (主要保護硬解適配層HAL代碼)
|-- libcore
|-- ndk
|-- device
|-- out (編譯完成後的代碼輸出與此目錄)
|-- packages (應用程序包)
|-- prebuilt (x86和arm架構下預編譯的一些資源)
|-- sdk (sdk及模擬器)
|-- system (文件系統庫、應用及組件——c語言)
`-- vendor (廠商定製代碼)
bionic 目錄
|-- libc (C庫)
| |-- arch-arm (ARM架構,包含系統調用匯編實現)
| |-- arch-x86 (x86架構,包含系統調用匯編實現)
| |-- bionic (由C實現的功能,架構無關)
| |-- docs (文檔)
| |-- include (頭文件)
| |-- inet
| |-- kernel (Linux內核中的一些頭文件)
| |-- netbsd (?netbsd系統相關,具體作用不明)
| |-- private (?一些私有的頭文件)
| |-- stdio (stdio實現)
| |-- stdlib (stdlib實現)
| |-- string (string函數實現)
| |-- tools (幾個工具)
| |-- tzcode (時區相關代碼)
| |-- unistd (unistd實現)
| `-- zoneinfo (時區信息)
|-- libdl (libdl實現,dl是動態鏈接,提供訪問動態鏈接庫的功能)
|-- libm (libm數學庫的實現,)
| |-- alpha (apaha架構)
| |-- amd64 (amd64架構)
| |-- arm (arm架構)
| |-- bsdsrc (?bsd的源碼)
| |-- i386 (i386架構)
| |-- i387 (i387架構?)
| |-- ia64 (ia64架構)
| |-- include (頭文件)
| |-- man (數學函數,後綴名為.3,一些為freeBSD的庫文件)
| |-- powerpc (powerpc架構)
| |-- sparc64 (sparc64架構)
| `-- src (源代碼)
|-- libstdc++ (libstdc++ C++實現庫)
| |-- include (頭文件)
| `-- src (源碼)
|-- libthread_db (多線程程序的調試器庫)
| `-- include (頭文件)
`-- linker (動態鏈接器)
`-- arch (支持arm和x86兩種架構)
bootable 目錄
|-- bootloader (適合各種bootloader的通用代碼)
| `-- legacy (估計不能直接使用,可以參考)
| |-- arch_armv6 (V6架構,幾個簡單的匯編文件)
| |-- arch_msm7k (高通7k處理器架構的幾個基本驅動)
| |-- include (通用頭文件和高通7k架構頭文件)
| |-- libboot (啟動庫,都寫得很簡單)
| |-- libc (一些常用的c函數)
| |-- nandwrite (nandwirte函數實現)
| `-- usbloader (usbloader實現)
|-- diskinstaller (android鏡像打包器,x86可生產iso)
`-- recovery (系統恢復相關)
|-- edify (升級腳本使用的edify腳本語言)
|-- etc (init.rc恢復腳本)
|-- minui (一個簡單的UI)
|-- minzip (一個簡單的壓縮工具)
|-- mttils (mtd工具)
|-- res (資源)
| `-- images (一些圖片)
|-- tools (工具)
| `-- ota (OTA Over The Air Updates升級工具)
`-- updater (升級器)
build目錄
|-- core (核心編譯規則)
|-- history (歷史記錄)
|-- libs
| `-- host (主機端庫,有android 「cp」功能替換)
|-- target (目標機編譯對象)
| |-- board (開發平台)
| | |-- emulator (模擬器)
| | |-- generic (通用)
| | |-- idea6410 (自己添加的)
| | `-- sim (最簡單)
| `-- proct (開發平台對應的編譯規則)
| `-- security (密鑰相關)
`-- tools (編譯中主機使用的工具及腳本)
|-- acp (Android "acp" Command)
|-- apicheck (api檢查工具)
|-- applypatch (補丁工具)
|-- apriori (預鏈接工具)
|-- atree (tree工具)
|-- bin2asm (bin轉換為asm工具)
|-- check_prereq (檢查編譯時間戳工具)
|-- dexpreopt (模擬器相關工具,具體功能不明)
|-- droiddoc (?作用不明,java語言,網上有人說和JDK5有關)
|-- fs_config (This program takes a list of files and directories)
|-- fs_get_stats (獲取文件系統狀態)
|-- iself (判斷是否ELF格式)
|-- isprelinked (判斷是否prelinked)
|-- kcm (按鍵相關)
|-- lsd (List symbol dependencies)
|-- releasetools (生成鏡像的工具及腳本)
|-- rgb2565 (rgb轉換為565)
|-- signapk (apk簽名工具)
|-- soslim (strip工具)
`-- zipalign (zip archive alignment tool)
dalvik目錄 dalvik虛擬機
.
|-- dalvikvm (main.c的目錄)
|-- dexmp (dex反匯編)
|-- dexlist (List all methods in all concrete classes in a DEX file.)
|-- dexopt (預驗證與優化)
|-- docs (文檔)
|-- dvz (和zygote相關的一個命令)
|-- dx (dx工具,將多個java轉換為dex)
|-- hit (?java語言寫成)
|-- libcore (核心庫)
|-- libcore-disabled (?禁用的庫)
|-- libdex (dex的庫)
|-- libnativehelper (Support functions for Android's class libraries)
|-- tests (測試代碼)
|-- tools (工具)
`-- vm (虛擬機實現)
development 目錄 (開發者需要的一些常式及工具)
|-- apps (一些核心應用程序)
| |-- BluetoothDebug (藍牙調試程序)
| |-- CustomLocale (自定義區域設置)
| |-- Development (開發)
| |-- Fallback (和語言相關的一個程序)
| |-- FontLab (字型檔)
| |-- GestureBuilder (手勢動作)
| |-- NinePatchLab (?)
| |-- OBJViewer (OBJ查看器)
| |-- SdkSetup (SDK安裝器)
| |-- SpareParts (高級設置)
| |-- Term (遠程登錄)
| `-- launchperf (?)
|-- build (編譯腳本模板)
|-- cmds (有個monkey工具)
|-- data (配置數據)
|-- docs (文檔)
|-- host (主機端USB驅動等)
|-- ide (集成開發環境)
|-- ndk (本地開發套件——c語言開發套件)
|-- pdk (Plug Development Kit)
|-- samples (演示程序)
| |-- AliasActivity ()
| |-- ApiDemos (API演示程序)
| |-- BluetoothChat (藍牙聊天)
| |-- BrowserPlugin (瀏覽器插件)
| |-- BusinessCard (商業卡)
| |-- Compass (指南針)
| |-- ContactManager (聯系人管理器)
| |-- CubeLiveWall** (動態壁紙的一個簡單常式)
| |-- FixedGridLayout (像是布局)
| |-- GlobalTime (全球時間)
| |-- HelloActivity (Hello)
| |-- Home (Home)
| |-- JetBoy (jetBoy游戲)
| |-- LunarLander (貌似又是一個游戲)
| |-- MailSync (郵件同步)
| |-- MultiResolution (多解析度)
| |-- MySampleRss (RSS)
| |-- NotePad (記事本)
| |-- RSSReader (RSS閱讀器)
| |-- SearchableDictionary (目錄搜索)
| |-- **JNI (JNI常式)
| |-- SkeletonApp (空殼APP)
| |-- Snake (snake程序)
| |-- SoftKeyboard (軟鍵盤)
| |-- Wiktionary (?維基)
| `-- Wiktionary**(?維基常式)
|-- scripts (腳本)
|-- sdk (sdk配置)
|-- simulator (?模擬器)
|-- testrunner (?測試用)
`-- tools (一些工具)
⑼ Android源代碼 請問,1,從網上下載的android源碼應該放在SDK哪個目錄下面,以什麼樣的格式
不知道你要把源碼放在SDk中 幹啥用,還有下載好源代碼的SDK啥意思,windows下下載不了源代碼,要在windows上裝個cygwin或者在虛擬機里裝個ubuntu
⑽ 安卓APP反編譯後的程序源代碼在哪裡
assets是html文件,lib是jar,res是資源文件。AndroidManifest是配置文件,源碼在smali和original裡面