android - use Toolbar as an action bar doesn't inflate menu -
i'm trying utilize toolbar action bar, , follow chris banes guide:
https://chris.banes.me/2014/10/17/appcompat-v21/
now next setup i've empty toolbar, seems getmenuinflater().inflate() doesn't work.
in activity i've:
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menuhome, menu); [...]
and in oncreate():
toolbar toolbar = (toolbar) findviewbyid(r.id.my_awesome_toolbar); setsupportactionbar(toolbar);
and layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:allmytv="http://schemas.android.com/apk/res-auto" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/linearlayoutmain" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <android.support.v7.widget.toolbar xmlns:allmytv="http://schemas.android.com/apk/res-auto" android:id="@+id/my_awesome_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorprimary" /> <com.astuetz.pagerslidingtabstrip android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="48dip" allmytv:pstsindicatorcolor="#f57c1d" /> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" > </android.support.v4.view.viewpager> </linearlayout>
where i'm wrong?
inorder utilize toolbar actionbar need set attribute windowactionbar false.
include next in styles.xml
<style name="appcompattheme" parent="@style/theme.appcompat.light.noactionbar"> <item name="windowactionbar">false</item> <item name="colorprimary">#4285f6</item> </style>
in manifest.xml under tag utilize above theme
android:theme="@style/appcompattheme"
i have used toolbar inflate menu:
toolbar.inflatemenu(r.menu.your_toolbar_menu);
android android-support-library android-toolbar
No comments:
Post a Comment