NRahman
NRahman

Reputation: 2757

Change the background of a Full Activity?

I have this Activity and a XML for constructing a listview. From the listview I can only design a single row but now I want to change the color of full background means the color of the full 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;
                }
            };

and the XML code is:

<?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>

Here #272727 changes the color of a single row; I want to change the background.

Upvotes: 0

Views: 120

Answers (1)

oks16
oks16

Reputation: 1294

In activity layout xml, use android:background attribute or In onCreate

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

Upvotes: 1

Related Questions