在Android中更改LinearLayout的背景 [英] Change background of LinearLayout in Android

查看:827
本文介绍了在Android中更改LinearLayout的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序.我想更改LinearLayout元素的背景.

I am working on an Android application. I want to change the background of a LinearLayout element.

我可以设置什么属性来更改其背景?

What attribute can I set in order to change its background?

推荐答案

如果要使用android的默认颜色代码通过xml进行设置,则需要执行以下操作:

If you want to set through xml using android's default color codes, then you need to do as below:

android:background="@android:color/white"

如果您在项目的colors.xml中指定了颜色,请使用:

If you have colors specified in your project's colors.xml, then use:

android:background="@color/white"

如果您要以编程方式进行操作,请执行以下操作:

If you want to do programmatically, then do:

linearlayout.setBackgroundColor(Color.WHITE);

这篇关于在Android中更改LinearLayout的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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