android - Changing a item background -


i need change background of item in app , didn't found thing it. use item & menu drawer need change titles background. know if use listview can change want if there way it. thank you

 <item          android:checkable="false"          android:title="@string/account">          <menu>              <item                  android:id="@+id/nav_member"                  android:icon="@drawable/ic_person_add_black_24dp"                  android:title="@string/member" />              <item                  android:id="@+id/nav_pay"                  android:icon="@drawable/ic_menu_credit_card_black_24dp"                  android:title="@string/pay" />              <item                  android:id="@+id/nav_fanclub"                  android:icon="@drawable/ic_menu_fanclub"                  android:title="@string/fanclub" />              <item                  android:id="@+id/nav_introduction"                  android:icon="@drawable/ic_menu_introduction"                  android:title="@string/introduction" />              <item                  android:id="@+id/nav_cards"                  android:icon="@drawable/ic_menu_cards"                  android:title="@string/cards" />              <item                  android:id="@+id/nav_points"                  android:icon="@drawable/ic_menu_points"                  android:title="@string/points" />          </menu>      </item>

drawer menu sadly not easy customize, can not in classic way du lack of parameters in initial conception.

to have create layout.xml named "design_navigation_item.xml"

then in layout should add own itemview extended class navigationmenuitemview

<?xml version="1.0" encoding="utf-8"?> <!--     layout should not rename, use directly design navigationview component. --> <your.package.mynavigationmenuitemview     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="?attr/listpreferreditemheightsmall"     android:paddingstart="?attr/listpreferreditempaddingleft"     android:paddingend="?attr/listpreferreditempaddingright"     android:foreground="?attr/selectableitembackground"     android:focusable="true"/> 

in mynavigationview class can override methods

public class mynavigationmenuitemview extends navigationmenuitemview {      private static final float menu_item_font_size_sp = 14.0f;      private checkedtextview mtextview;      public mynavigationmenuitemview(context context) {         this(context, null);     }      public mynavigationmenuitemview(context context, attributeset attrs) {         this(context, attrs, 0);     }      public mynavigationmenuitemview(context context, attributeset attrs, int defstyleattr) {         super(context, attrs, defstyleattr);         if (isineditmode()) {             return;         }         mtextview = (checkedtextview) findviewbyid(android.support.design.r.id.design_menu_item_text);     }      @override     public void initialize(menuitemimpl itemdata, int menutype) {          super(itemdata, menutype);          if (itemdata.gettitle().equals("some specific title") {              // specific style changes on textview          }     }      @override     public void settextappearance(int textappearance) {         // text cutomization         mtextview.settextsize(typedvalue.complex_unit_sp, menu_item_font_size_sp);         mtextview.setbackgroundcolor(contextcompat.getcolor(getcontext(), r.color.menuitembackgroundcolor));     } } 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -