There is a side menu and its markup:

<TextView android:id="@+id/listTitle" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:paddingBottom="16dp" android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" android:paddingTop="16dp" android:textColor="@color/list_group_title" android:textSize="16dp" android:background="@drawable/head" android:gravity="center_vertical"/> 

Here is the line:

  android:background="@drawable/head" 

Which sets the menu background. How to dynamically change this background through Java? How to change the color I know:

  TextView tv = (TextView) vv.findViewById(R.id.listTitle); tv.setBackgroundColor(R.color.icon_film); 

And what if I need a picture with drawable ? Changing " color " to " drawable " will not work.

    1 answer 1

    Use the setBackgroundResource(int resId)

     TextView tv = ...; tv.setBackgroundResource(R.drawable.SOME_RES); 
    • Yes, already saw, thanks. - Alexey