android - Set toolbar to FragmentActivity -


there similar lots of questions tried didn't help.

followed splash screen app shows activity viewpager. called activity fragmentcontainer because contains viewpager. because fragmentcontainer extends fragmentacitity cannot use setsupportactionbar() set custom toolbar.

fragment_container.xml this:

<relativelayout>      <com.astuetz.pagerslidingtabstrip         android:background="?attr/colorprimary"         android:id="@+id/tabs"         android:layout_below="@id/toolbar_top_fc"         android:layout_height="?attr/actionbarsize"         android:layout_width="match_parent"         android:textcolorprimary="@android:color/white"         app:pstsindicatorcolor="@color/coloraccent"         app:pstspaddingmiddle="true"         app:pststabpaddingleftright="24dp" />      <android.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_below="@id/tabs"         android:layout_height="match_parent"         android:layout_width="match_parent">  </relativelayout> 

fragmentcontanier.java

public class fragmentcontainer extends fragmentactivity {      viewpager viewpager = null;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.fragment_container);          viewpager = (viewpager) findviewbyid(r.id.pager);         fragmentmanager fragmentmanager = getsupportfragmentmanager();         viewpager.setadapter(new myadapter(fragmentmanager));         viewpager.setcurrentitem(1);          //tabs         pagerslidingtabstrip tabs = (pagerslidingtabstrip) findviewbyid(r.id.tabs);         tabs.setviewpager(viewpager);     } }  class myadapter extends fragmentpageradapter {      public myadapter(fragmentmanager fm) {         super(fm);     }      @override     public fragment getitem(int position) {         fragment fragment = null;         if (position == 0) {             fragment = new fragmentedit();         } else if (position == 1) {             fragment = new fragmentmain();         } else if (position == 2) {             fragment = new fragmentsavedmessages();         }         return fragment;     }      @override     public int getcount() {         return 3;     }      @override     public charsequence getpagetitle(int position) {         charsequence title = null;         if (0 == position) {             title = "edit";         } else if (1 == position) {             title = "main";         } else if (2 == position) {             title = "save";         }         return title;     } } 

i need implementing custom actionbar this. please guise.

any appreciated. feel free suggest edits.

you cannot have separate toolbar fragment. can customise parent activity toolbar according fragment, set in oncreateview of fragment sethasoptionsmenu(true); , inflate custom menu items in

@override public void oncreateoptionsmenu(       menu menu, menuinflater inflater) {    inflater.inflate(r.menu.activity_itemdetail, menu); } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -