Android的 - 如何设置所有屏幕的背景颜色? [英] Android - how to set background color of all screens?

查看:798
本文介绍了Android的 - 如何设置所有屏幕的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习Android和到目前为止,我一直专注于功能性,但现在我开始布局工作。

I have been learning Android and so far I have been focused on functionality, but now I am starting to work with layouts.

我想知道什么是保持风格的字体和颜色的最佳实践。我做了我所用,以改变如按钮单独的元素颜色的colors.xml文件,但我不知道怎么的Andr​​oid开发者想组织自己的风格。

I was wondering what is the best practice to maintaining styles of fonts and colors. I made a colors.xml file which I have used to change colors on seperate elements like buttons, but I am not sure how Android wants developers to organize their styles.

例如,我想所有屏幕具有相同的背景颜色。我怎么做?有什么事情,我需要为每个活动布局XML?或其他地方?我该如何实现呢?

For example, I would like all screens to have the same background color. How do I do that? Is it something I need to specify for each Activity layout xml? Or elsewhere? How do I accomplish it?

谢谢!

推荐答案

一个快速简便的方法,以确保每一项活动都有相同的背景颜色,是为您创造活动中使用的一个主题。这主题将指定的android:windowBackground

A quick and easy way to make sure every activity has the same background color, is to create a theme for your activities to use. That theme would specify the android:windowBackground.

首先定义值的色彩/ colors.xml

First define the color in values/colors.xml

<resources>
    <color name="background">#FF0000 </color>
</resources>

创建RES /值的themes.xml文件引用该颜色:

Create a themes.xml file in res/values that references that color:

<resources>
 <style name="MyTheme" parent="@android:style/Theme.Light"> 
  <item name="android:windowBackground">@color/background</item>
 </style>
</resources>

...然后在AndroidManifest.xml中指定该为主题的为您的活动使用。

... and then in your AndroidManifest.xml specify this as the theme for your activities to use.

 <activity
        android:name=".MyActivity"
        android:theme="@style/MyTheme" />

这篇关于Android的 - 如何设置所有屏幕的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆