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

  • 相关阅读:
    Cocos Creator Editor 第一个编辑器扩展(扩展菜单)
    Rider 设置
    unity 使用GameObject.SetActive(true)激活对象时,会在SetActive内部调用Awake和OnEnable函数
    unity/C# 结构体属性使用set和get访问器应注意的问题
    unity 自定义AssetImporter导入指定资源
    Duilib部分源码解析
    TreeView树形控件的使用
    JQuery 文档资源收集
    排序和搜索(一)插入排序系列
    字符相关类型和编码概念
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/7211405.html
Copyright © 2011-2022 走看看