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

时间: 2024-08-05 06:43:21

Android之Window的相关文章

Android Starting Window(Preview Window)

当打开一个Activity时,如果这个Activity所属的应用还没有在运行,系统会为这个Activity所属的应用创建一个进程,但进程的创建与初始化都需要时间,在这个动作完成之前系统要做什么呢?如果没有任何反应的话,如果程序初始化的时间很长,用户可能还以为没有点到相应的位置.但此时所启动的程序还没初始化完,既无法显示程序,又不能停在原处不做任何动作,怎么办?这就有了Starting Window的概念,也可以称之为Preview Window. Starting Window就是一个用于在应用

Android 之 Window、WindowManager 与窗口管理

其实在android中真正展示给用户的是window和view,activity在android中所其的作用主要是处理一些逻辑问题,比如生命周期的管理.建立窗口等.在android中,窗口的管理还是比较重要的一块,因为他直接负责把内容展示给用户,并和用户进行交互.响应用户的输入等. 在讲窗口管理时,有必要先说下ViewManager这个接口,这个接口主要有以下的实现子接口和实现类,分别是:WindowManager和ViewGroup里面还有三个重要的方法: * addView(); * upd

(转) Android的Window类

Android的Window类 2011-03-25 10:02 by Keis, 110 visits, 网摘, 收藏, 编辑 Android的Window类(一)  Android的GUI层并不复杂.它的复杂度类似于WGUI这类基于布局和对话框的GUI,与MFC.QT等大型框架没有可比性,甚至飞漫魏永明的MiniGUI都比它复杂许多.您也许会问,这样简单的GUI如何实现浏览器呢?原因很简单,浏览器有自己一套GUI.Android浏览器(WebKit)的GUI和Android的GUI实用同一套

android设置window背景透明的bug

今天解决了一个bug,在我们产品中的界面上快速点击某个控件(点击完要跳转到其他Activity),会调起其他的app! 最初的想法是,使用了overridependingtransition,导致在切换过程中,App失去了对touch实践的捕获,结果去掉之后还是无法解决. 也没有什么特别好的想法,这种没有日志的bug最难解决!不停的重试,无意中发现,在Activity切换过程中,使用退出动画(缩放)的Activity 后面都是透明的,launcher都显示了出来,虽然面积不大,但还是被我发现了.

Android中Window添加View的底层原理

一,WIndow和windowManager Window是一个抽象类,它的具体实现是PhoneWindow,创建一个window很简单,只需要创建一个windowManager即可,window具体实现在windowManagerService中,windowManager和windowManagerService的交互是一个IPC的过程. 下面是用windowManager的例子: mFloatingButton = new Button(this); mFloatingButton.set

Android View, Window,Activity概念区分(2)

(1)View:最基本的UI组件,表示屏幕上的一个矩形区域. (2)Window: 表示一个窗口,不一定有屏幕那么大,可以很大也可以很小:它包含一个View tree和窗口的layout 参数.View tree的root View可以通过getDecorView得到.还可以设置Window的Content View. (3)Activity:Activity包含一个Window,该Window在Activity的attach方法中通过调用PolicyManager.makeNewWindo创建

QT 5.3.2 for android 在window XP 32bit 和 WIN 8.1 64bit 上面环境搭建 (一)

安装QT 5.3.2 for windows 经过了不少折腾,总算把它安装OK ,helloworld 跑起来了. Windows xp 需要的安装包: 1.android-ndk-r9d-windows-x86.zip 2.adt-bundle-windows-x86-20140321.zip 3.apache-ant-1.9.4-bin.zip 4.JDK的包,我的是jdk1.7.0_15 ,以前就安装好的. 5.qt-opensource-windows-x86-android-5.3.2

[Android] 关于Window Overscan

Overscan的概念 对于电视机,有一个Overscan的概念,如下图,所谓Overscan区域,就是电视机屏幕四周某些不可见的区域,这是电视机的特性.并且,Overscan的具体值也没有一个明确的标准,不同的电视机厂家的Overscan的值也各不相同. 而对于普通的LCD,由于并没有Overscan的概念,所以设想,将一块没有设置Overscan的Framebuffer显示到有Overscan的电视机上,必定四周有一部分Overscan的区域被切除到无法显示出来. 所以在Android 4.

Android Popup Window 居于控件上方突出显示

public class TestPopupWindowActivity extends PopupWindow { Activity context; public TestPopupWindowActivity(Activity context, View v) { super(context); this.context = context; RelativeLayout mContentView = new RelativeLayout(context); RelativeLayout.