Side menu is expressed through TextView :

  <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"/> 

In MainActivity by pressing a button, the action is performed:

  public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } switch (id) { case R.id.action_settings: TextView tv = (TextView) findViewById(R.id.listTitle); tv.setBackgroundResource(R.drawable.minus); return true; default: return super.onOptionsItemSelected(item); } 

Which changes the design of the TextView menu from head to minus . Everything works, but only the uppermost, first menu section changes, the rest remain the same background - head . What could be the problem? After all, in fact, I use the setBackgroundResource method setBackgroundResource change the entire TextView design. How to change all sections completely? If you change directly in the TextView markup:

with

  android:background="@drawable/head" 

on

  android:background="@drawable/minus" 

then everything works.

  • Little is clear. Do you have a ListView menu with these TextView as items? - JuriySPb
  • Yes exactly. ExpandableListView - Alexey

1 answer 1

Changing the contents of the list elements is necessary not directly referring to the markup, but through the adapter, changing in it the value of the -l variable, which determines how the markup element is drawn in the adapter.

Those.

  1. In the adapter, get a variable of type boolean .
  2. Depending on its value, set the adapter's getView / getChildView / getGroupView drawing method to the desired background for the TextView
  3. In the adapter, set the method to change the value of this variable.
  4. When you press the menu button, call the method for changing the value of the adapter variable and force it to be redrawn by calling the notifyDataSetChanged() method

Your method does not work, because You always find only one markup element by ID, and you have many of them with the same ID in the list. That's why only one element changes