我需要以编程方式从RelativeLayout更改背景颜色。
在XML文件中我做到了:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/milayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/negro"
android:orientation="horizontal"
android:padding="5dip"
>
然后在活动文件中,我试图声明布局以便稍后更改RelativeLayout的背景颜色,正如我在SO中的其他帖子中看到的那样。
RelativeLayout MyLayout = (RelativeLayout) findViewById(R.layout.milayout);
但我得到一个错误:“在类型'布局'中创建字段milayout”
我做错了什么?
答案 0 :(得分:1)
查看您的代码
RelativeLayout MyLayout =(RelativeLayout)findViewById(R. layout .milayout);
更改为
RelativeLayout myLayout = (RelativeLayout) findViewById(R.id.milayout);