title: How to change the background drawable of a layout in java?
body: <p>I am trying to change the background of message item in a chat app but instead of changing the background of the message item it changes everything around the message on its line. I have tried other solutions to this problem but they all end up like below.</p>
  
  <p>Example:</p>
  
  <p><a href="https://i.stack.imgur.com/Qvni5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qvni5.png" alt="enter image description here"></a></p>
  
  <p>Here is the code for the spawning of the item:</p>
  
  <pre><code> mUserMsg = new FirebaseRecyclerAdapter&lt;ChatMessage, ViewHolder&gt;(ChatMessage.class,R.layout.chat_item_sent,ViewHolder.class,mRef)
      {
          @Override
          protected void populateViewHolder(ViewHolder view, ChatMessage message, int position) {
              LinearLayout messageLine = view.layout;
              TextView messgaeText = view.message;
              TextView senderText = view.sender;
              ImageView leftPic = view.leftPic;
              View mView= view.fucker;
  
  
              if (message.getUserID().equals(USER_ID))
              {
                  messageLine.setGravity(Gravity.END);
                  leftPic.setVisibility(View.GONE);
  
                  messageLine.setBackground(ContextCompat.getDrawable(mView.getContext(),R.drawable.round_corners_sent));
  
                  messgaeText.setText(message.getMessageText());
                  senderText.setText(message.getUserID());
              }
              else
              {
                  messageLine.setGravity(Gravity.LEFT);
  
                  Picasso.with(getApplicationContext()).load(Uri.parse(picURL)).fit().centerCrop().into(leftPic);
  
  
                  messgaeText.setText(message.getMessageText());
                  senderText.setText(message.getUserID());
              }
  
          }
      };
  
      recyclerView.setLayoutManager(mLinearLayoutManager);
      recyclerView.setAdapter(mUserMsg);
  
  }
  </code></pre>
  
  <p>This is the drawable I am trying to change to:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;corners android:radius="5dp"/&gt;
  
      &lt;stroke
          android:width="40dp"
          android:color="#a8bbcf"/&gt;
  
      &lt;solid android:color="#a8bbcf"/&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p>Here is the chat item layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/messageLine"
      android:orientation="horizontal"&gt;
  
      &lt;de.hdodenhof.circleimageview.CircleImageView
          android:id="@+id/leftMessagePic"
          android:layout_width="50dp"
          android:layout_height="50dp"
          android:layout_marginLeft="10dp"
          android:layout_marginTop="10dp"
          android:src="@mipmap/ic_launcher" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/individMessageLayout"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:layout_marginRight="0dp"
          android:layout_marginTop="10dp"
          android:background="@drawable/round_corners_received"
          android:orientation="vertical"
          android:paddingBottom="10dp"
          android:paddingLeft="20dp"
          android:paddingRight="20dp"
          android:paddingTop="10dp"&gt;
  
          &lt;ImageView
              android:id="@+id/imageMessage"
  
              android:layout_width="100dp"
              android:layout_height="100dp"
              android:visibility="gone" /&gt;
  
  
          &lt;TextView
              android:id="@+id/messageTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:maxWidth="200dp"
              android:textAppearance="?android:attr/textAppearanceSmall"
              android:textColor="@color/black"
              android:textSize="18sp"
              android:textStyle="normal|bold"
              tools:text="Message" /&gt;
  
          &lt;TextView
              android:id="@+id/senderTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="left"
              android:textColor="@color/black"
              android:textSize="12sp"
              tools:text="Sender" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>