Android之Window,androidwindow

來源:互聯網
上載者:User

Android之Window,androidwindow

window表示的是一個抽象視窗類別,該類只是一個抽象視窗類別,其具體的唯一實作類別是PhoneWindow類。Window對象的擷取通過在Activity中調用getWindow()方法擷取到Window對象;該類定義了一個CallBack介面,用於處理使用者的訊息資料,該介面的方法有:dispatchKeyEvent,dispatchTouchEvent等,
他設定了一組通用的視窗操作api。比如setContentView方法,實際上Activity中的setContentView方法是調用的Activity內部的Window中的setContentView方法來實現的,除了這個方法之外,還有findViewById()方法也是調用的Window方法的findViewById()方法。
在Window類中,定義了一組常量值,用於表示視窗的樣式:常量值如下所示:

  /** Flag for the "options panel" feature.  This is enabled by default.表示有功能表項目,預設有功能表項目 */    public static final int FEATURE_OPTIONS_PANEL = 0;    /** Flag for the "no title" feature, turning off the title at the top     *  of the screen.表示無標題列,也就是應用程式上面沒有標題列 */    public static final int FEATURE_NO_TITLE = 1;    /** Flag for the progress indicator feature進度條 */    public static final int FEATURE_PROGRESS = 2;    /** Flag for having an icon on the left side of the title bar在標題列的左側有表徵圖 */    public static final int FEATURE_LEFT_ICON = 3;    /** Flag for having an icon on the right side of the title bar在標題列的右側有表徵圖 */    public static final int FEATURE_RIGHT_ICON = 4;    /** Flag for indeterminate progress 不確定的進度條,比如圓圈狀的等待條*/    public static final int FEATURE_INDETERMINATE_PROGRESS = 5;    /** Flag for the context menu.  This is enabled by default.操作功能表 */    public static final int FEATURE_CONTEXT_MENU = 6;    /** Flag for custom title. You cannot combine this feature with other title features. 自訂的標題列,該屬性不能和其他屬性合用*/    public static final int FEATURE_CUSTOM_TITLE = 7;    /**     * Flag for enabling the Action Bar.     * This is enabled by default for some devices. The Action Bar     * replaces the title bar and provides an alternate location     * for an on-screen menu button on some devices.     */    public static final int FEATURE_ACTION_BAR = 8;      public static final int FEATURE_ACTION_BAR_OVERLAY = 9;    /**     * Flag for specifying the behavior of action modes when an Action Bar is not present.     * If overlay is enabled, the action mode UI will be allowed to cover existing window content.     */    public static final int FEATURE_ACTION_MODE_OVERLAY = 10;    /**     * Max value used as a feature ID     * @hide     */    public static final int FEATURE_MAX = FEATURE_ACTION_MODE_OVERLAY;    /** Flag for setting the progress bar's visibility to VISIBLE */    public static final int PROGRESS_VISIBILITY_ON = -1;    /** Flag for setting the progress bar's visibility to GONE */    public static final int PROGRESS_VISIBILITY_OFF = -2;    /** Flag for setting the progress bar's indeterminate mode on */    public static final int PROGRESS_INDETERMINATE_ON = -3;    /** Flag for setting the progress bar's indeterminate mode off */    public static final int PROGRESS_INDETERMINATE_OFF = -4;    /** Starting value for the (primary) progress */    public static final int PROGRESS_START = 0;    /** Ending value for the (primary) progress */    public static final int PROGRESS_END = 10000;    /** Lowest possible value for the secondary progress */    public static final int PROGRESS_SECONDARY_START = 20000;    /** Highest possible value for the secondary progress */

實際上我們熟知的Activity與Widnow類聯絡很緊密,每個Activity中都有自己的Window類。在每個Activity類的內部都有一個私人變數private Window mWindow;該對象的賦值是在Activity的attach()方法中賦值的,通過mWindow = PolicyManager.makeNewWindow(this);這個語句來為對象賦值,而attach方法的調用是在ActivityThread中建立Activity對象時調用的。PolicyManager.makeNewWindow(this);該方法歸根結底只是建立出一個PhoneWindow對象賦值給mWindow對象。另外Window類可以接受使用者的訊息處理的,而Activity通過實現Window類的CallBack介面從而也能夠處理使用者的訊息。
window對象的一些常用方法:
setContentView(),activity中setContentView就是調用該方法
findViewById(),activity中findViewById就是調用該方法
getLayoutInflater(),activity中getLayoutInflater就是調用該方法
getContext(),返回當前的上下文環境
getWindowManager()返回視窗管理器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.