Attach android:actionLayout on res/menu-how to invoke it from .xml to .java -


i'm bit confused res/menu.xml folder.

i want cart on action bar having textview counter(which increment on every click). have relativelayout contains imageview , textview named badge_counter_text. want attach on res/menu/main.xml is:

<item         android:id="@+id/rightslider"         android:orderincategory="100"         android:actionlayout="@layout/badge_counter_text"         android:showasaction="always"         android:actionviewclass="android.widget.imagebutton"         android:icon="@drawable/cart"         android:title="cart"/> 

my badge_counter_text.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/badge_layout_cartcounter"     android:layout_width="48dp"     android:layout_height="fill_parent"     android:layout_gravity="right" >      <textview         android:id="@+id/add_item_counter"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentright="true"         android:layout_marginright="15dp"         android:textappearance="@android:style/textappearance.small"         android:layout_torightof="@+id/imageview1"         android:background="@android:color/holo_red_dark"         android:hint="0"         android:textcolor="@color/white" />      <imagebutton         android:id="@+id/imageofcart"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:clickable="true"         android:src="@drawable/cart" />  </relativelayout> 

my code:

@override public boolean oncreateoptionsmenu(final menu menu) {      menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.main, menu);      btncart = (imagebutton)menu.finditem(r.id.rightslider).getactionview();     txtcount = (textview)menu.finditem(r.id.badge_layout_cartcounter).getactionview().findviewbyid(r.id.add_item_counter);      //... } 

the problem i'm getting null on txtcount object.

try use toolbar purpose. can add own layout this

<android.support.v7.widget.toolbar android:id="@+id/nav_toolbar" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/blue">  <imagebutton     android:id="@+id/btn_toolbar_back"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="left"     android:layout_marginleft="@dimen/spacing_tiny"     android:background="@drawable/filter_nav_prev"/>  <relativelayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="center">      <textview         android:id="@+id/toolbar_label"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerhorizontal="true"         android:gravity="center_horizontal"         android:textallcaps="false"         android:textcolor="@color/background_white"         android:textsize="@dimen/font_big"/> </relativelayout> 

or try code action bar

actionbar mactionbar = getactionbar();     mactionbar.setdisplayshowhomeenabled(false);     mactionbar.setdisplayshowtitleenabled(false);     layoutinflater minflater = layoutinflater.from(this);      view mcustomview = minflater.inflate(r.layout.badge_layout_cartcounter, null);      mactionbar.setcustomview(mcustomview);     mactionbar.setdisplayshowcustomenabled(true); 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -