从code更改活动背景 [英] Change activity background from code

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

问题描述

我有一个背景的活动:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="@drawable/background_fingerboard" />

如何更改背景图片从code?实际上我用单声道,而且Java的样品也将是有帮助的。

How can I change background image from code? I actually use mono, but Java samples will also be helpful.

推荐答案

先添加的LinearLayout ID作为在布局的xml:

first add LinearLayout id as in your layout xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayoutid" 
android:minWidth="25px"
android:minHeight="25px"
android:background="@drawable/background_fingerboard" 

在code部分集背景::

and in code part set background as::

LinearLayout  linearLayout = (LinearLayout) findViewById(R.id.linearLayoutid);
 linearLayout.setBackgroundResource(R.drawable.background_fingerboard);

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

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