android - CardView toolbars -
i have recyclerview contains cardviews.
i add toolbar each of cardviews , behave main toolbar:
[icon] [title] .......... [button] [button] [menu]
i've seen here (http://blog.grafixartist.com/create-a-card-toolbar/) possible set actual android.support.v7.widget.toolbar object inside cardview. relies on setsupportactionbar(...) inflate menu , respond actions.
do think it's possible reproduce behaviour in each of cardviews?
you don't need setsupportactionbar cardviews toolbars until need set actionbar specific actions up/back navigation actions.
take @ fine example (link whole page below):
thanks gabriele help. here working code:
activity :
public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_mai); toolbar toolbar = (toolbar) findviewbyid(r.id.card_toolbar); toolbar.settitle("card toolbar"); if (toolbar != null) { // inflate menu toolbar.inflatemenu(r.menu.main); toolbar.setonmenuitemclicklistener(new toolbar.onmenuitemclicklistener() { @override public boolean onmenuitemclick(menuitem menuitem) { return true; } }); } toolbar maintoolbar = (toolbar) findviewbyid(r.id.toolbar_main); if (toolbar != null) { // inflate menu maintoolbar.inflatemenu(r.menu.main); maintoolbar.setonmenuitemclicklistener(new toolbar.onmenuitemclicklistener() { @override public boolean onmenuitemclick(menuitem menuitem) { return true; } }); } } }layout xml file:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v7.widget.toolbar android:id="@+id/toolbar_main" android:layout_width="match_parent" android:layout_height="@dimen/action_bar_size_x2" android:background="@android:color/holo_orange_dark" android:minheight="?attr/actionbarsize" /> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/toolbar_main" android:layout_marginleft="15dp" android:layout_marginright="15dp" android:layout_margintop="@dimen/action_bar_size" android:orientation="vertical" > <android.support.v7.widget.cardview android:layout_width="match_parent" android:layout_height="match_parent" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.v7.widget.toolbar android:id="@+id/card_toolbar" android:layout_width="match_parent" android:layout_height="@dimen/action_bar_size" android:background="@android:color/white" /> <view android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="@string/app_name" android:textsize="24sp" /> </linearlayout> </android.support.v7.widget.cardview> </linearlayout> </relativelayout>make sure activity theme extending
theme.appcompat.light.noactionbar.here like:
few things note:
- if using card elevation need altar margin top card aligns main toolbar
- i still seeing 1-2 pixel margin between bottom of main toolbar , card toolbar. not sure in case. now, aligning manually.
notice author of post hadn't used @ all, i'm pretty sure don't need implementation idea
hope help

Comments
Post a Comment