zoukankan      html  css  js  c++  java
  • 关于android Activity的 theme

        关注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了.

  • 相关阅读:
    java的继承---包装器与自动装箱
    linux开机启动过程,很多人说的不太清楚的看看。
    黑盒测试/三角形(OC)
    git 忽略一些文件的提交
    volley 框架的使用
    如何通过阿里百川的集成,以及manifest的权限配置完成淘客商品详情页的链接
    抓取网站访问者的QQ号码
    写写东西吧
    Android 强制实现下线功能
    Android 新闻显示界面且适应平板
  • 原文地址:https://www.cnblogs.com/leipei2352/p/2171856.html
Copyright © 2011-2022 走看看