如何为所有活动设置背景? [英] How to set background for all activities?
问题描述
如何为adnroid应用程序中的所有活动设置背景并保持其长宽比?
How to set background for all activities in adnroid application and keep it's aspect ratio?
我正在使用android:windowBackground
样式,但是我不知道如何保持背景图像的宽高比.
I am using android:windowBackground
in style, but I don't know, how to keep aspect ratio for my background image.
是否只有办法为所有活动手动添加带有背景的ImageView
?
Is there only way to add ImageView
with background for all activities manually?
推荐答案
您也许可以在styles.xml
<style name="AppTheme.FullBackground" parent="AppTheme">
<item name="android:background">#757575</item>
</style>
(其中AppTheme
可能是您已经定义的主题,而我只是在其中使用了灰色,但是它可以是可绘制的)
(Where AppTheme
might be a theme you already defined, and I just used a grey color there, but it can be a drawable)
然后将其添加到您的清单
Then add to your Manifest
<activity
android:name=".FooActivity"
android:theme="@style/AppTheme.FullBackground">
</activity>
由于无论如何都必须向清单中添加活动,所以这是检查所有活动是否都具有背景的好方法.当然,您仍然可以扩展BaseActivity
,仅让BaseActivity
类维护主题设置.
Since you have to add activities to the Manifest anyway, this is a good way to check if all the activities have the background. You, of course, could still extend the BaseActivity
and only have the BaseActivity
class maintain the theme setting.
这篇关于如何为所有活动设置背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!