在Android中以编程方式删除背景可绘制 [英] Remove background drawable programmatically in Android

查看:50
本文介绍了在Android中以编程方式删除背景可绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式删除背景可绘制对象@drawable/bg. 有没有办法做到这一点?

I want to remove the background drawable @drawable/bg programmatically. Is there a way to do that?

当前,我的布局中包含以下XML:

Currently, I have the following XML in my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/widget29"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/bg">

</RelativeLayout>

推荐答案

尝试一下

RelativeLayout relative = (RelativeLayout) findViewById(R.id.widget29);
relative.setBackgroundResource(0);

RelativeLayout文档

这篇关于在Android中以编程方式删除背景可绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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