2016-09-20 19 views
7

我正在挖掘Android的來源,通過查找系統如何識別@null在佈局中提到的關鍵字的答案。例如,Android如何在佈局中解釋@null關鍵字?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:background="@null" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

到目前爲止,我跟着這條路線:

  1. TypedArray#getDrawable(int index)
  2. ResourcesImpl#getValue(@AnyRes int id, TypedValue outValue, boolean resolveRefs)
  3. AssetManager#getResourceValue(@AnyRes int resId, int densityDpi, @NonNull TypedValue outValue,boolean resolveRefs)
  4. AssetManager#loadResourceValue(int ident, short density, TypedValue outValue,boolean resolve)

我嘗試到f ind在source code的JNI執行AssetManager loadResourceValue方法,但是我沒有成功。

如果有人能指出Android如何解析@null標記,我將不勝感激。

在此先感謝!

回答

1

您正在搜索通過NDK暴露的AssetManager前端。根本沒有JNI功能。 android.util.AssetManager的JNI包裝是here

ResTable類用於實際解析和解析。如果你深入挖掘一下 - 你可以找到lines,其中@null被處理。

+0

哇,代碼看起來很瘋狂!塞里奧,謝謝你的回覆! –