Emk*_*key 124 layout android background
我想以编程方式删除背景drawable(@ drawable/bg).有没有办法做到这一点?
目前,我的布局中有以下XML:
<?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>
Mar*_*ues 293
试试这个
RelativeLayout relative = (RelativeLayout) findViewById(R.id.widget29);
relative.setBackgroundResource(0);
检查RelativeLayout文档中的setBackground函数
Ada*_*zyk 67
setBackgroundResource(0)是最好的选择.从文档:
将背景设置为给定资源.资源应引用Drawable对象或0以删除背景.
它适用于所有地方,因为它是自API 1以来.
setBackground很久以后,在API 16中添加,所以如果你minSdkVersion的价格低于16,它将无法运作.
Sur*_*jaj 47
这有助于我删除背景颜色,希望它可以帮助某人.
setBackgroundColor(Color.TRANSPARENT)
试试这个代码:
imgView.setImageResource(android.R.color.transparent); 
这也有效:
imgView.setImageResource(0); 
但要小心这个不起作用:
imgView.setImageResource(null); 
| 归档时间: | 
 | 
| 查看次数: | 113702 次 | 
| 最近记录: |