更改完整活动的背景?

时间:2013-07-05 09:05:14

标签: android image background

我有这个Activity和一个用于构建listview的XML。从listview我只能设计一行,但现在我想改变完整背景的颜色意味着完整Activity的颜色。

public class MyActivity extends Activity implements
            AdapterView.OnItemClickListener, View.OnClickListener {

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ListView list = new ListView(this);
            setContentView(list);

            String[] items = { "Tom", "Sally", "Bill", "John", "Santiago",
                    "Isabella" };

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    R.layout.review, R.id.textView1, items) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View row = super.getView(position, convertView, parent);


                    View text = row.findViewById(R.id.seemore);
                    text.setTag(position);
                    text.setOnClickListener(MyActivity.this);



                    View left = row.findViewById(R.id.imageView1);
                    left.setBackgroundResource(R.drawable.newapture);
                    left.setTag(position);
                    left.setOnClickListener(MyActivity.this);


                    return row;
                }
            };

,XML代码是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="#272727">

    <ImageView
        android:id="@+id/one"
        android:layout_width="140dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/title"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="14dp"

        android:clickable="true"
      />

</RelativeLayout>

这里#272727改变了单行的颜色;我想改变背景。

1 个答案:

答案 0 :(得分:1)

在活动布局xml中,使用 android:background 属性或 在 onCreate

getWindow().setBackgroundDrawableResource(R.drawable.bg_img);