`
baobaoupup
  • 浏览: 470705 次
文章分类
社区版块
存档分类
最新评论

去掉默认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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics