去掉默认ACTIVITY背景图

当你设置你的UI在activity上时 by calling setContentView() ,android增加你的VIEW在activity的WINDOW上。
这个窗口并不只包含你的VIEW。
                            DecorView
                            LinearLayout
                       FrameLayout    FrameLayout
                         TextView         FrameLayout
                                               ..              ....
DecorView实际上hold这window的背景drawble.可以通过getWindow().setBackgroundDrawable()
从activity中改变windows的背景图。如果你用默认的android theme,一个默认的背景drawable将被设置到你的activity上。
这个drawable目前是一个ColorDrawable(好像是灰黑色的)。对于大多数application,这个背景图能工作很好可以被保留。
但是能影响点性能。
如果你在你的activity上设置一个不透明的背景图,那么在你后面的DecorView的背景图也就是默认窗口的背景图就不可见了,那么
画他就没意义了。
删除这个背景很容易:This drawable is simply referenced by the theme:

<resources>
<style name="Theme.Shelves" parent="android:Theme">
<item name="android:windowBackground">@drawable/background_shelf</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>





android:theme="@style/Theme.NoBackground"
to your

<activity />
or <application />
tag

这个技巧很好的对于用MapView
, a WebView
or any other full screen opaque

view.

用一个theme去改变windows的背景也是个很好的办法能给改善启动activity的性能。

如果你的application简单的设置背景在XML layout里或者在ONCREATE里,用户将能看到application启动时带着默认的theme和

他的黑背景。你设置的背景只是appear after the inflation of the content view and the first layout/drawing

pass.



以下是设置背景(窗口背景,不是activity背景,如果你设置了窗口背景,那么activity就不用设置了)

in res/drawable/background_shelf.xml
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/shelf_panel"
android:tileMode="repeat" />This drawable is simply referenced by the theme:

<resources>
<style name="Theme.Shelves" parent="android:Theme">
<item name="android:windowBackground">@drawable/background_shelf</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值