actionbar源碼
A. android源碼右上角的menu鍵如何去掉
你不要在程序中寫這一句requestWindowFeature(Window.FEATURE_NO_TITLE);,把它換為
ActionBar actionBar=getSupportActionBar();
actionBar.hide();這兩句就行了,這樣你在標題欄就被隱藏起來,而且你點擊Menu鍵也不會出錯了!你試一下,我的API也是19,我這樣寫就解決了。我的應用是一定要extends ActionBarActivity,所以最後只能找到這種方法,不能把它改為extends Activity.
B. Android - View 繪制流程
我們知道,在 Android 中,View 繪制主要包含 3 大流程:
Android 中,主要有兩種視圖: View 和 ViewGroup ,其中:
雖然 ViewGroup 繼承於 View ,但是在 View 繪制三大流程中,某些流程需要區分 View 和 ViewGroup ,它們之間的操作並不完全相同,比如:
對 View 進行測量,主要包含兩個步驟:
對於第一個步驟,即求取 View 的 MeasureSpec ,首先我們來看下 MeasureSpec 的源碼定義:
MeasureSpec 是 View 的一個公有靜態內部類,它是一個 32 位的 int 值,高 2 位表示 SpecMode(測量模式),低 30 位表示 SpecSize(測量尺寸/測量大小)。
MeasureSpec 將兩個數據打包到一個 int 值上,可以減少對象內存分配,並且其提供了相應的工具方法可以很方便地讓我們從一個 int 值中抽取出 View 的 SpecMode 和 SpecSize。
一個 MeasureSpec 表達的是:該 View 在該種測量模式(SpecMode)下對應的測量尺寸(SpecSize)。其中,SpecMode 有三種類型:
對 View 進行測量,最關鍵的一步就是計算得到 View 的 MeasureSpec ,子View 在創建時,可以指定不同的 LayoutParams (布局參數), LayoutParams 的源碼主要內容如下所示:
其中:
LayoutParams 會受到父容器的 MeasureSpec 的影響,測量過程會依據兩者之間的相互約束最終生成子View 的 MeasureSpec ,完成 View 的測量規格。
簡而言之,View 的 MeasureSpec 受自身的 LayoutParams 和父容器的 MeasureSpec 共同決定( DecorView 的 MeasureSpec 是由自身的 LayoutParams 和屏幕尺寸共同決定,參考後文)。也因此,如果要求取子View 的 MeasureSpec ,那麼首先就需要知道父容器的 MeasureSpec ,層層逆推而上,即最終就是需要知道頂層View(即 DecorView )的 MeasureSpec ,這樣才能一層層傳遞下來,這整個過程需要結合 Activity 的啟動過程進行分析。
我們知道,在 Android 中, Activity 是作為視圖組件存在,主要就是在手機上顯示視圖界面,可以供用戶操作, Activity 就是 Andorid 中與用戶直接交互最多的系統組件。
Activity 的基本視圖層次結構如下所示:
Activity 中,實際承載視圖的組件是 Window (更具體來說為 PhoneWindow ),頂層View 是 DecorView ,它是一個 FrameLayout , DecorView 內部是一個 LinearLayout ,該 LinearLayout 由兩部分組成(不同 Android 版本或主題稍有差異): TitleView 和 ContentView ,其中, TitleView 就是標題欄,也就是我們常說的 TitleBar 或 ActionBar , ContentView 就是內容欄,它也是一個 FrameLayout ,主要用於承載我們的自定義根布局,即當我們調用 setContentView(...) 時,其實就是把我們自定義的布局設置到該 ContentView 中。
當 Activity 啟動完成後,最終就會渲染出上述層次結構的視圖。
因此,如果我們要求取得到子View 的 MeasureSpec ,那麼第一步就是求取得到頂層View(即 DecorView )的 MeasureSpec 。大致過程如下所示:
經過上述步驟求取得到 View 的 MeasureSpec 後,接下來就可以真正對 View 進行測量,求取 View 的最終測量寬/高:
Android 內部對視圖進行測量的過程是由 View#measure(int, int) 方法負責的,但是對於 View 和 ViewGroup ,其具體測量過程有所差異。
因此,對於測量過程,我們分別對 View 和 ViewGroup 進行分析:
綜上,無論是對 View 的測量還是 ViewGroup 的測量,都是由 View#measure(int widthMeasureSpec, int heightMeasureSpec) 方法負責,然後真正執行 View 測量的是 View 的 onMeasure(int widthMeasureSpec, int heightMeasureSpec) 方法。
具體來說, View 直接在 onMeasure(...) 中測量並設置自己的最終測量寬/高。在默認測量情況下, View 的測量寬/高由其父容器的 MeasureSpec 和自身的 LayoutParams 共同決定,當 View 自身的測量模式為 LayoutParams.UNSPECIFIED 時,其測量寬/高為 android:minWidth / android:minHeight 和其背景寬/高之間的較大值,其餘情況皆為自身 MeasureSpec 指定的測量尺寸。
而對於 ViewGroup 來說,由於布局特性的豐富性,只能自己手動覆寫 onMeasure(...) 方法,實現自定義測量過程,但是總的思想都是先測量 子View 大小,最終才能確定自己的測量大小。
當確定了 View 的測量大小後,接下來就可以來確定 View 的布局位置了,也即將 View 放置到屏幕具體哪個位置。
View 的布局過程由 View#layout(...) 負責,其源碼如下:
View#layout(...) 主要就做了兩件事:
ViewGroup 的布局流程由 ViewGroup#layout(...) 負責,其源碼如下:
可以看到, ViewGroup#layout(...) 最終也是通過 View#layout(...) 完成自身的布局過程,一個注意的點是, ViewGroup#layout(...) 是一個 final 方法,因此子類無法覆寫該方法,主要是 ViewGroup#layout(...) 方法內部對子視圖動畫效果進行了相關設置。
由於 ViewGroup#layout(...) 內部最終調用的還是 View#layout(...) ,因此, ViewGroup#onLayout(...) 就會得到回調,用於處理 子View 的布局放置,其源碼如下:
由於不同的 ViewGroup ,其布局特性不同,因此 ViewGroup#onLayout(...) 是一個抽象方法,交由 ViewGroup 子類依據自己的布局特性,擺放其 子View 的位置。
當 View 的測量大小,布局位置都確定後,就可以最終將該 View 繪制到屏幕上了。
View 的繪制過程由 View#draw(...) 方法負責,其源碼如下:
其實注釋已經寫的很清楚了, View#draw(...) 主要做了以下 6 件事:
我們知道,在 Activity 啟動過程中,會調用到 ActivityThread.handleResumeActivity(...) ,該方法就是 View 視圖繪制的起始之處:
可以看到, ActivityThread.handleResumeActivity(...) 主要就是獲取到當前 Activity 綁定的 ViewManager ,最後調用 ViewManager.addView(...) 方法將 DecorView 設置到 PhoneWindow 上,也即設置到當前 Activity 上。 ViewManager 是一個介面, WindowManager 繼承 ViewManager ,而 WindowManagerImpl 實現了介面 WindowManager ,此處的 ViewManager.addView(...) 實際上調用的是 WindowManagerImpl.addView(...) ,源碼如下所示:
WindowManagerImpl.addView(...) 內部轉發到 WindowManagerGlobal.addView(...) :
在 WindowManagerGlobal.addView(...) 內部,會創建一個 ViewRootImpl 實例,然後調用 ViewRootImpl.setView(...) 將 ViewRootImpl 與 DecorView 關聯到一起:
ViewRootImpl.setView(...) 內部首先關聯了傳遞過來的 DecorView (通過屬性 mView 指向 DecorView 即可建立關聯),然後最終調用 requestLayout() ,而 requestLayout() 內部又會調用方法 scheleTraversals() :
ViewRootImpl.scheleTraversals() 內部主要做了兩件事:
Choreographer.postCallback(...) 會申請一次 VSYNC 中斷信號,當 VSYNC 信號到達時,便會回調 Choreographer.doFrame(...) 方法,內部會觸發已經添加的回調任務, Choreographer 的回調任務有以下四種類型:
因此, ViewRootImpl.scheleTraversals(...) 內部通過 mChoreographer.postCallback(Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null) 發送的非同步視圖渲染消息就會得到回調,即回調 mTra
C. android 的action bar有什麼作用
下面是一個actionbar的使用截圖,來源於android學習手冊,360手機助手中可下載,裡面有108個例子,源碼還有文檔
Action bar是一個標識應用程序和用戶位置的窗口功能,並且給用戶提供操作和導航模式。在大多數的情況下,當你需要突出展現用戶行為或全局導航的activity中使用action bar,因為action bar能夠使應用程序給用戶提供一致的界面,並且系統能夠很好根據不同的屏幕配置來適應操作欄的外觀。你能夠用ActionBar的對象的API來控制操作欄的行為和可見性,這些API被添加在Android3.0(API 級別 11)中。
Action bar的主要目的是:
1.提供一個用於識別應用程序的標示和用戶的位置的專用空間。
這個空間的左邊是應用的圖標或logo,以及Activity的標題。但是,如果是像當前選擇的標簽這樣的標識當前View對象的導航標簽,你可以選擇刪除Activity的標題。
2.在不同的應用程序之間提供一致的導航和視覺體驗。
Action bar提供了用於Fragment間切換的內置導航標簽。它還提供了一個用於替換導航模式或優化當前視覺效果(如按照不同條件排序的列表)的下拉列表。
3.突出Activity的關鍵操作(如「搜索」、「創建」、「共享」等),並且在可預見的方法內給用戶提供快捷的訪問。
對於關鍵的用戶操作,你能夠通過把選項菜單項作為操作項直接放到操作欄中,從而提供快捷的訪問。操作項目還能提供一個操作窗口,這個窗口給更直接的操作行為提供一個嵌入的窗口部件。沒有改進成操作項的菜單項在溢出菜單中還是有效的,用戶既可以使用設備上的菜單按鈕(設備上有按鈕的時候),也可以使用操作欄中的溢出菜單按鈕(當設備上不包含菜單按鈕時)來顯示這些操作項目。
上面的總結一下:Action bar就是替換3.0以前的tittle bar和menu。
圖1. Honeycomb Gallery應用中的操作欄,從左邊開始,依次是logo、導航選項標簽和操作項(在右邊插入的一個懸浮菜單按鈕)。
Note:If you're looking for information about the contextual action bar for displaying contextual action items, see theMenuguide.
Action Bar Design For design guidelines, read Android Design'sAction Barguide.
添加Action Bar
從Android3.0(API級別 11)開始,Action bar被包含在所有的使用Theme.Hole主題的Activity(或者是這些Activity的子類)中,當targetSdkVersion或minSdkVersion屬性被設置為「11」或更大的數值是,這個主題是默認的主題一。如:
[html] view plain print?
<manifest...>
<uses-sdkandroid:minSdkVersion="4"
android:targetSdkVersion="11"/>
...
</manifest>
<manifest ... >
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="11" />
...
</manifest>
在這個例子中,應用程序要求最小的API版本級別是4(Android 1.6),但是它還要求了目標API版本級別是11(Android 3.0)。這樣,當應用程序運行在Android3.0或更高的版本上時,系統就會給每個Activity應用holographic 主題,這樣,每個Activity就會包含Action bar。
如果你想使用ActionBar API來進行添加導航模式和修改操作欄樣式的操作,你應該把minSdkVersion屬性設置為「11」或更大的值。有一些方法可以使你的應用支持更舊的Android版本,同時在API等級為11或更高的API等級的機器的使你的應用支持一些Action bar apis。為了保持後向兼容,請參考邊框內的內容(邊框內容如下)。
Remaining backward-compatible
If you want to provide an action bar in your applicationandremain compatible with versions of Android older than 3.0, you need to create the action bar in your activity's layout (because theActionBarclass is not available on older versions).
To help you, theAction Bar Compatibilitysample app provides an API layer and action bar layout that allows your app to use some of theActionBarAPIs and also support older versions of Android by replacing the traditional title bar with a custom action bar layout.
刪除Action bar
如果你不想要Action bar,把Activity的主題設置為Theme.Holo.NoActionBar就可以了,如:
[html] view plain print?
<activityandroid:theme="@android:style/Theme.Holo.NoActionBar">
<activity android:theme="@android:style/Theme.Holo.NoActionBar">
或者使用Action bar的 hide()方法,如下:
[java] view plain print?
ActionBaractionBar=getActionBar();
actionBar.hide();
ActionBar actionBar = getActionBar();
actionBar.hide();
當Action bar隱藏時,系統會調整你的Activity來填充當前有效的屏幕空間。你能夠使用show()方法來再次顯示操作欄。
在隱藏和刪除Action bar時,要當心為了適應被Action bar佔用的空間而導致的Activity的重新布局。如果你的Activity有規律的隱藏和顯示Action bar,你可能想要使用覆蓋模式。覆蓋模式在Activity的頂部描畫操作欄,而不是在它們所擁有的屏幕的區域。這樣,在Action bar隱藏和重新顯示時,你的布局保持不變。要使用覆蓋模式,就要給Activity創建一個主題,並且把android:windowActionBarOverlay屬性設置為true。
提示:如果你有一個刪除了Action bar的定製化的Activity主題,它把android:windowActionBar樣式屬性設置為false。但是,如果你使用了刪除Action bar的一個主題,那麼,創建窗口將不允許Action bar再顯示,因此,你不能在以後給這個Activity添加Action bar---因為getActionBar()方法將返回null。
添加操作項
有些時候,你可能想要讓用戶直接訪問選項菜單中的一個項目,因此你要把應該在Action bar中顯示的菜單項作為一個操作項來聲明。操作項能夠能夠包含一個圖標或文本標題。如果一個菜單項不作為一個操作項顯示,那麼系統就會把它放到懸浮菜單中。懸浮菜單既可以通過設備的Menu按鈕來顯示,也可以在Action bar中一個額外的按鈕來顯示。
當Activity首次啟動時,系統會調用onCreateOptionsMenu()方法給你的Activity組裝Action bar和懸浮菜單。在這個回調方法中應該載入在XML文件中定義的菜單項資源,如:
[java] view plain print?
@Override
(Menumenu){
MenuInflaterinflater=getMenuInflater();
inflater.inflate(R.menu.main_activity,menu);
returntrue;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity, menu);
return true;
}
圖2. 帶有圖標和文本標題的兩個操作項,和懸浮菜單按鈕。
在XML文件中,你能夠通過給<item>元素聲明android:showAsAction=」ifRoom」屬性,請求把一個菜單項作為一個操作項來顯示。用這種方式,只在有有效的空間時,菜單項才能顯示在Action bar中。如果沒有足夠的空間,這個菜單項會顯示在懸浮菜單中。
如果你的菜單項支持標題和圖標---帶有android:title和android:icon屬性---那麼默認情況下,操作項僅顯示圖標。如果你要顯示文本標題,就要給android:showAsAction屬性添加withText設置,如:
D. Android 完全隱藏狀態欄方法
Android 完全隱藏狀態欄方法 https://blog.csdn.net/ljbphoebe/article/details/88179576
1. 隱藏ActionBar:
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.hide();
}
如果是繼承AppCompatActivity,就用getSupportActionBar()。
2. 隱藏狀態欄
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
通過這兩個步就可以全屏顯示啟動頁了。
然而,當開始動態申請許可權,彈出系統的許可權提示對話框後,狀態欄又重新露出來了。我日,不是隱藏了嗎?怎麼又出來了,什麼鬼?
通過查看源碼的解釋:
/**
* Request that the visibility of the status bar or other screen/window
* decorations be changed.
*
* <p>This method is used to put the over device UI into temporary modes
* where the user's attention is focused more on the application content,
* by dimming or hiding surrounding system affordances. This is typically
* used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY
* Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content
* to be placed behind the action bar (and with these flags other system
* affordances) so that smooth transitions between hiding and showing them
* can be done.
*
* <p>Two representative examples of the use of system UI visibility is
* implementing a content browsing application (like a magazine reader)
* and a video playing application.
*
* <p>The first code shows a typical implementation of a View in a content
* browsing application. In this implementation, the application goes
* into a content-oriented mode by hiding the status bar and action bar,
* and putting the navigation elements into lights out mode. The user can
* then interact with content while in this mode. Such an application should
* provide an easy way for the user to toggle out of the mode (such as to
* check information in the status bar or access notifications). In the
* implementation here, this is done simply by tapping on the content.
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java
* content}
*
* <p>This second code sample shows a typical implementation of a View
* in a video playing application. In this situation, while the video is
* playing the application would like to go into a complete full-screen mode,
* to use as much of the display as possible for the video. When in this state
* the user can not interact with the application; the system intercepts
* touching on the screen to pop the UI out of full screen mode. See
* {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code.
*
* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java
* content}
*
* @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE},
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN},
* {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION},
* {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, {@link #SYSTEM_UI_FLAG_IMMERSIVE},
* and {@link #SYSTEM_UI_FLAG_IMMERSIVE_STICKY}.
*/
從釋義上可以知道,setSystemUiVisibility()是用於使系統UI進入一種臨時的模式,目的是使用戶的注意力關注於應用程序的內容上。所以單獨一個Activity這樣設置是可以全屏顯示的,這個只對當前的Activity有效。可是當申請系統許可權使,彈出的對話框是系統的Activity,通過adb shell mpsys activity 來看,當前最頂端的Activity已經是GrantPermissionsActivity。
Run #2: ActivityRecord{2b99111 u0 com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity t141}
而這個GrantPermissionsActivity,我們並無法去設置它的setSystemUiVisibility()。所以這種方法不奏效。
通過和同事討論,後來找到一種方法,可以實現我們的需求。
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
這種方法是OK的。
它的源碼釋義是:
/**
* Set the flags of the window, as per the
* {@link WindowManager.LayoutParams WindowManager.LayoutParams}
* flags.
*
* <p>Note that some flags must be set before the window decoration is
* created (by the first call to
* {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
* {@link #getDecorView()}:
* {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
* {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}. These
* will be set for you based on the {@link android.R.attr#windowIsFloating}
* attribute.
*
* @param flags The new window flags (see WindowManager.LayoutParams).
* @param mask Which of the window flag bits to modify.
* @see #addFlags
* @see #clearFlags
*/
public void setFlags(int flags, int mask) {}
仔細分析發現,這個是設置整個當前Window的,而setSystemUiVisibility()聚焦於顯示Activity內容的,還是有差別的。
/**
* Window flag: hide all screen decorations (such as the status bar) while
* this window is displayed. This allows the window to use the entire
* display space for itself -- the status bar will be hidden when
* an app window with this flag set is on the top layer. A fullscreen window
* will ignore a value of {@link #SOFT_INPUT_ADJUST_RESIZE} for the window's
* {@link #softInputMode} field; the window will stay fullscreen
* and will not resize.
*
* <p>This flag can be controlled in your theme through the
* {@link android.R.attr#windowFullscreen} attribute; this attribute
* is automatically set for you in the standard fullscreen themes
* such as {@link android.R.style#Theme_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Black_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Light_NoTitleBar_Fullscreen},
* {@link android.R.style#Theme_Holo_NoActionBar_Fullscreen},
* {@link android.R.style#Theme_Holo_Light_NoActionBar_Fullscreen},
* {@link android.R.style#Theme_DeviceDefault_NoActionBar_Fullscreen}, and
* {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_Fullscreen}.</p>
*/
public static final int FLAG_FULLSCREEN = 0x00000400;
從釋義上得知,設置這個flag可以隱藏所有的屏幕修飾,像status bar,用於Window使用整個顯示屏。這個完全是我們的目的了。
E. 請問FadingActionBar怎麼使用他的源碼下了以後一直有空指針,但是都報他的包,有哪位大
賄賂賄賂1
F. 如何在android 的actionbar中添加返回按鈕
點擊事件裡面執行finish消除這一個activity,上一個activity自然就出來了,
另外一個傻辦法,A跳到B的時候傳一個自己的action,B返回的時候直接跳轉到這個action就好了.
G. github 上有什麼價值的android 源碼
1. ActionBarSherlock
ActionBarSherlock應該算得上是GitHub上最火的Android開源項目了,它是一個獨立的庫,通過一個API和主題,開發者就可以很方便地使用所有版本的Android動作欄的設計模式。
對於Android
4.0及更高版本,ActionBarSherlock可以自動使用本地ActionBar實現,而對於之前沒有ActionBar功能的版本,基於
Ice Cream Sandwich的自定義動作欄實現將自動圍繞布局。能夠讓開發者輕松開發一款帶動作欄(Action
bar)的應用,並且適用於Android 2.x及其以上所有版本。
詳情請參考:ActionBarSherlock
2. facebook-android-sdk
Facebook SDK for Android是一個開源庫,允許開發者將Facebook集成到所開發的Android應用中。
如果想要獲取更多關於示例、文檔、將SDK集成到App中、源代碼等信息,可直接登陸Facebook Developers查看。
3. SlidingMenu(SlidingMenu Demos)
SlidingMenu是一個開源的Android庫,能夠讓開發者輕松開發一款應用,實現類似於Google+、Youtube和Facebook應用中非常流行的滑動式菜單。
使用SlidingMenu的Android應用:
Foursquare
Rdio
Plume
VLC for Android
ESPN ScoreCenter
MLS MatchDay
9GAG
Wunderlist 2
The Verge
MTG Familiar
Mantano Reader
Falcon Pro (BETA)
MW3 Barracks
4. cocos2d-x
在移動開發領域,將Cocos2D-X用於主流iOS/Android游戲開發的公司、開發團隊多不勝數。cocos2d-x是一個開源的支持多平
台的2D游戲框架,使用C++開發,基於cocos2d-iphone,在MIT許可證下發布。主分支在GitHub上使用OpenGL ES
2.0渲染,而舊版gles11分支則使用OpenGL ES 1.1渲染。
支持iOS、Android、Windows Phone 8、Bada、BlackBerry、Marmalade、Windows、Linux等多個平台。支持C++、Lua、JavaScript編程語言。
5. android
GitHub Android App是
GitHub開源的Android客戶端,支持Issues、Gists,並集成了新聞Feed,能夠讓你及時跟進組織及關注的開發者、庫等。同時,該應
用還提供了一個用戶快速訪問你所創建、監控及發布issue的面板,可查看並將問題加入到收藏夾,可對標簽、里程碑和任務進行過濾配置。
android資源庫包含了GitHub Android App的所有源代碼。
6. Android-ViewPagerIndicator
ViewPager指針項目,在使用ViewPager的時候能夠指示ViewPager所在的位置,就像Google Play中切換的效果一樣,還能使用在應用初始化的介紹頁面。
兼容Android支持庫的ViewPager及ActionBarSherlock,最初是基於Patrik Åkerfeldt的ViewFlow,開發者可以直接登陸Google Play下載該項目的演示應用。
7. MonoGame
MonoGame是一個Microsoft XNA 4.x Framework的開源跨平台實現。用於讓XNA開發者將他們在Xbox
360、Windows & Windows Phone上開發的游戲移植到iOS、Android、Mac OS
X、Linux及Windows 8 Metro上,目前,PlayStation Mobile & Raspberry
PI的開發正在進行中。
詳情請參考:MonoGame
8. Android-PullToRefresh
該項目用於為Android提供一個可重用的下拉刷新部件。它最初來源於Johan Nilsson的庫(主要是圖形、字元串和動畫),但這些後來都已被取代。
9. android-async-http
android-async-http是Android上的一個非同步、基於回調的HTTP客戶端開發包,建立在Apache的HttpClient庫上。
10. Android-Universal-Image-Loader
Android上最讓人頭疼的莫過於從網路獲取圖片、顯示、回收,任何一個環節有問題都可能直接OOM,這個項目或許能幫到你。
Universal Image Loader for Android的目的是為了實現非同步的網路圖片載入、緩存及顯示,支持多線程非同步載入。它最初來源於Fedor Vlasov的項目,且自此之後,經過大規模的重構和改進。
11. GreenDroid
GreenDroid最初是由Cyril Mottier發起,是一個Android的UI開發類庫,能夠讓UI開發更加簡便,並且在應用中始終保持一致。
詳情請參考:Cyril Mottier's Blog
12. Anki-Android
AnkiDroid是一個免費、開源的Android的快閃記憶體應用,可直接從Google Play進行下載。
詳情請參考:ankidroid
13. android-actionbar
Action
bar是一個標識應用程序和用戶位置的窗口功能,並且給用戶提供操作和導航模式。在大多數的情況下,當開發者需要突出展現用戶行為或在全局導航的
activity中使用action bar,因為action
bar能夠使應用程序給用戶提供一致的界面,且系統能夠很好地根據不同的屏幕配置來適應操作欄的外觀。
Action bar的主要目的:
提供一個用於識別應用程序的標示和用戶的位置的專用空間。
在不同的應用程序之間提供一致的導航和視覺體驗。
突出Activity的關鍵操作,並且在可預見的方法內給用戶提供快捷的訪問。
14. android-viewflow
android-viewflow是Android平台上的一個視圖切換的效果庫,ViewFlow相當於Android UI部件提供水平滾動的ViewGroup,使用Adapter進行條目綁定。
15. android-mapviewballoons
當使用Android地圖外部庫(com.google.android.maps)時,android-mapviewballoons會提供一個簡單的方式來對地圖覆蓋進行標注,就是一個簡單的信息氣泡。
它由BalloonOverlayView組成,是一個代表顯示你的MapView及BalloonItemizedOverlay的氣泡的視圖,BalloonItemizedOverlay是ItemizedOverlay的一個抽象擴展。
16. PushSharp
一個向iOS(iPhone/iPad APNS)、Android(C2DM和GCM)、Windows Phone和Windows 8設備發送推送通知的伺服器端庫。
17. androidannotations
Android Annotations是一個開源的框架,用於加速 Android應用的開發,可以讓你把重點放在功能的實現上,簡化了代碼,提升了可維護性。
18. HockeyKit
Hockey是一個iOS Ad-Hoc自動更新框架。蘋果App
Store中的所有App都可以使用它,它能夠顯著地提高Beta測試的整個過程,分為兩部分:伺服器和客戶端框架。伺服器組件需要所有腳本,但在沒有客
戶端庫的情況下,也可以單獨工作。它提供一個Web介面,Beta測試者可以使用它來安裝最新的AdHoc配置文件,也可以直接在設備上通過Safari
安裝最新的Beta版本。
只需在伺服器上安裝一次服務端,就可以處理包標識符不同的多個應用程序(有開發者強烈建議對Debug、AdHoc Beta和AppStore發布版使用不同的包標識符)。
默認當App啟動或喚醒時,客戶端會從伺服器檢測更新,用戶可以在設置對話框中進行修改:一天一次或手動檢查更新。
除了支持iOS,HokeyKit也支持Android平台,不過Android版還處在Alpha階段,支持OTA及應用內更新。
為HockeyKit用戶提供伺服器託管服務。
19. android-menudrawer
Android上的菜單展示風格各異,其中用得最多且體驗最好的莫過於左右滑動來顯示隱藏的菜單,android-menudrawer是一個滑動
式菜單實現,允許用戶在應用當中實現無縫導航。該項目具有多種菜單展示效果,其中最常見的就是通過屏幕邊緣拖動或點擊動作欄的「向上」按鈕顯示。
實現功能:
菜單可以沿著四個邊放置。
支持附加一個始終可見、不可拖動的菜單。
菜單的內容和整個窗口都可以隱藏。
可用於XML布局。
顯示當前可見屏幕的指示器。
20. android-flip
Aphid FlipView是一個能夠實現Flipboard翻頁效果的UI組件。
H. 如何獲得ActionBar的背景顏色
之前寫了一篇文章如何修改背景色。現在需要修改標題顏色,發現直接在background下面寫android:textColor不行。得在backgroud下面再寫一個style。修改values-v14文件夾下的style.xml文件
I. android 怎麼使用windowsplitactionbar
究竟是如何將R.layout.xxx_view.xml這樣的布局文件載入到Android系統的view層次結構中的(即我們常說的view樹)。
這期間一方面自己研究了下源碼,另一方面也在網上搜索了下相關文章,發現了2篇很不錯的同主題文章,推薦給大家:
http://blog.csdn.net/qinjuning/article/details/7226787 & http://blog.csdn.net/bigconvience/article/details/28626631。
我們在開發中接觸的最早的應該算是Activity.setContentView(int resourceId)方法了,我們知道在Activity的onCreate方法
中調用此方法可以把我們提供的根布局文件載入到activity中並顯示出來。很自然地我們就從它開始說起吧,廢話不多說上代碼:
復制代碼
/**
* Set the activity content from a layout resource. The resource will be
* inflated, adding all top-level views to the activity.
*
* @param layoutResID Resource ID to be inflated.
*
* @see #setContentView(android.view.View)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setContentView(int layoutResID) { // 實際上其內部都是delegate給了getWindow()方法
getWindow().setContentView(layoutResID);
initActionBar();
}
/**
* Set the activity content to an explicit view. This view is placed
* directly into the activity's view hierarchy. It can itself be a complex
* view hierarchy. When calling this method, the layout parameters of the
* specified view are ignored. Both the width and the height of the view are
* set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use
* your own layout parameters, invoke
* {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)}
* instead.
*
* @param view The desired content to display.
*
* @see #setContentView(int)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setContentView(View view) {
getWindow().setContentView(view);
initActionBar();
}
/**
* Set the activity content to an explicit view. This view is placed
* directly into the activity's view hierarchy. It can itself be a complex
* view hierarchy.
*
* @param view The desired content to display.
* @param params Layout parameters for the view.
*
* @see #setContentView(android.view.View)
* @see #setContentView(int)
*/
public void setContentView(View view, ViewGroup.LayoutParams params) {
getWindow().setContentView(view, params);
initActionBar();
}
/**
* Add an additional content view to the activity. Added after any existing
* ones in the activity -- existing views are NOT removed.
*
* @param view The desired content to display.
* @param params Layout parameters for the view.
*/
public void addContentView(View view, ViewGroup.LayoutParams params) {
getWindow().addContentView(view, params);
initActionBar();
}
復制代碼
我們可以看到setContentView方法內部都delegate給了getWindow()方法,這里順便也把addContentView提及了下,setXXX有
替換的意思,addXXX則是往後面在加一個,即以前的還在。緊接著我們看下Activity里的window是咋來的吧,代碼如下:
復制代碼
private Window mWindow; // Activity的一個欄位
/**
* Retrieve the current {@link android.view.Window} for the activity.
* This can be used to directly access parts of the Window API that
* are not available through Activity/Screen.
*
* @return Window The current window, or null if the activity is not
* visual.
*/
public Window getWindow() {
return mWindow;
}
final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token,
Application application, Intent intent, ActivityInfo info, CharSequence title,
Activity parent, String id, NonConfigurationInstances lastNonConfigurationInstances,
Configuration config) {
attach(context, aThread, instr, token, 0, application, intent, info, title, parent, id,
lastNonConfigurationInstances, config);
}
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
Application application, Intent intent, ActivityInfo info,
CharSequence title, Activity parent, String id,
NonConfigurationInstances lastNonConfigurationInstances,
Configuration config) {
attachBaseContext(context);
mFragments.attachActivity(this, mContainer, null);
mWindow = PolicyManager.makeNewWindow(this); // 注意這行代碼,這里實際上創建了一個PhoneWindow的實例
mWindow.setCallback(this); // window對象里的Callback介面的實現是Activity
mWindow.getLayoutInflater().setPrivateFactory(this);
if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
mWindow.setSoftInputMode(info.softInputMode);
}
if (info.uiOptions != 0) {
mWindow.setUiOptions(info.uiOptions);
}
mUiThread = Thread.currentThread();
mMainThread = aThread;
mInstrumentation = instr;
mToken = token;
mIdent = ident;
mApplication = application;
mIntent = intent;
mComponent = intent.getComponent();
mActivityInfo = info;
mTitle = title;
mParent = parent;
mEmbeddedID = id;
= lastNonConfigurationInstances;
mWindow.setWindowManager(
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
mToken, mComponent.flattenToString(),
(info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
if (mParent != null) {
mWindow.setContainer(mParent.getWindow());
}
mWindowManager = mWindow.getWindowManager();
mCurrentConfig = config;
}
復制代碼
這里我們順便解釋下Window、Activity、View的區別和聯系:
首先Window是個抽象類,封裝了頂層Window樣式和行為的策略類,它的實例被用作頂層view加到window manager裡面,它提供了
標準的UI策略,如背景、標題欄、默認的key處理邏輯等等。在Android系統中有一個唯一的實現PhoneWindow,當我們需要window的
時候就會有一個PhoneWindow的實例被new出來。每個Activity都有一個與之關聯的window對象,Activity在其上繪制其UI。
Window對象里又有一個mDecor對象,它是window里的頂層view(也就是說view的層次結構從它開始,它是view樹的根)。
更多的解釋可以參考這個問題: android-window 。
J. Android 應用程序,調用 setText運行停止,怎麼辦
Android 應用程序,調用 setText運行停止是由於系統進程意外關閉導致的,解決方法如下:
1. 最簡單的可以重啟手機就可以了,由於重啟手機系統進程又會重新運行的了。
2. 重啟手機還是不行的話可以恢復出廠設置,打開手機設置,選擇重置打開,選擇恢復出廠設置,手機重啟後就可以了。