Sunday, 15 September 2013

java - Android L support library Toolbar appears under views -



java - Android L support library Toolbar appears under views -

i have mainactivity.xml has framelayout , within has toolbar

<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" tools:ignore="mergerootframe" > <android.support.v7.widget.toolbar android:id = "@+id/toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minheight="?attr/actionbarsize" android:background="?attr/colorprimary" /> </framelayout>

inside mainactivity.java, have this

public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (savedinstancestate == null) { getfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()) .commit(); } toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); }

based on tutorial here, http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html, should have custom toolbar acts actionbar. however, toolbar appears happens under fragments add together in block. toolbar supposed appear above them , shift them downwards, views cover actionbar toolbar. glitch or forgetting something? worked before broken reason.

the toolbar needs outside of framelayout going hold fragment so:

<linearlayout 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:orientation="vertical"> <android.support.v7.widget.toolbar android:id = "@+id/toolbar" android:layout_height="wrap_content" android:layout_width="match_parent" android:minheight="?attr/actionbarsize" android:background="?attr/colorprimary" /> <framelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity" tools:ignore="mergerootframe" > </framelayout> </linearlayout>

java android android-layout material-design

No comments:

Post a Comment