菜鸟lei的学习成长空间

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

    关注android Activity的theme(或者该翻译为主题),是由两个网上的android面试题引发的.
    1.activity的生命周期
    2.怎样把一个Activity设置成窗口的样式

    先说说activity的生命周期.两个Activity在切换时,第二个Activity如果把第一个Activity遮盖住了,那第一个Activity必然会调用onStop方法,而如果没有遮盖,则在调用了onPause方法后就不再调用onStop方法.这一点,我在先前有专门去探索过.http://www.cnblogs.com/leipei2352/archive/2011/08/09/2132279.html
    因此在学习Activity生命周期时,为了让第二个Activity不完全把第一个Activity遮盖住,我设置了第二个Activity的theme:        
        <activity android:name=".activity02" android:theme="@android:style/Theme.Dialog"></activity>
    再说说由这个theme引出的其它知识点.设置这个窗口theme,其实我是从教材里看到的,但教材中并未提到其他theme.我在eclipse中打开theme的引用后,新打开了一个文件: C:\Program Files\Android\android-sdk\platforms\android-8\data\res\values\theme.xml .在这个文件中定义了不少我还不了解的theme.不过还好,每个theme项都在前面有描述.
    本想列在此处,发现有点不现实,那么多,全列在这地方,难免有刷字数的嫌疑.对theme比较感兴趣话,可以自己去读这个文件.我只在这里列一个比较有意思的theme的定义.

   1: <!-- Default theme for translucent activities, that is windows that allow you
   2:      to see through them to the windows behind.  This sets up the translucent
   3:      flag and appropriate animations for your windows.  -->
   4: <style name="Theme.Translucent">
   5:     <item name="android:windowBackground">@android:color/transparent</item>
   6:     <item name="android:colorBackgroundCacheHint">@null</item>
   7:     <item name="android:windowIsTranslucent">true</item>
   8:     <!-- Note that we use the base animation style here (that is no
   9:          animations) because we really have no idea how this kind of
  10:          activity will be used. -->
  11:     <item name="android:windowAnimationStyle">@android:style/Animation</item>
  12: </style>
     从这个theme的定义来看,一个Activity设置了这样的theme后,它是半透明的,因此定义了这样的theme的Activity不能完全把先前的Activity遮盖住.这样来看,先前那个Activity启动了第二个Activity之后,不会调用onStop方法哦.我试了下,嘿,果然是这样.
    后面要多关注下android Activity的theme了.

posted on 2011-09-08 22:06  菜鸟-雷  阅读(10182)  评论(0编辑  收藏  举报