zoukankan      html  css  js  c++  java
  • Android之Window

    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()返回窗体管理器

  • 相关阅读:
    html 上传图片前预览
    php获取当月天数及当月第一天及最后一天、上月第一天及最后一天实现方法
    php 计算 pdf文件页数
    php 获取半年内每个月的订单数量, 总价, 月份
    php 获取两个数组之间不同的值
    小程序支付功能
    关于nginx的Job for nginx.service failed because the control process exited with error code.错误
    linux 安装 Apollo
    MongoDB待续。。。
    ABP vNext...待续
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7211405.html
Copyright © 2011-2022 走看看