material design - Toolbar is not shown in android application -
i have started migrate old app material design , decided use toolbar instead of actionbar more customization.i tried add toolbar 1 activity following code :
layout.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" 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" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorprimary" android:minheight="?attr/actionbarsize" > </android.support.v7.widget.toolbar> <android.support.design.widget.tablayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="48dip" android:background="@drawable/background_tabs" /> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tabs" tools:context=".mainactivity" /> </relativelayout>
mainactivity.java
public class mainactivity extends appcompatactivity { private viewpager pager; private mypageradapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); myapp.tracker().send(new hitbuilders.eventbuilder("ui", "open") .setlabel("main") .build()); // set toolbar replace actionbar. toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); } }
style.xml
<style name="mytheme.base" parent="@style/theme.appcompat.light.noactionbar"> <!-- app branding color app bar --> <item name="colorprimary">@color/redlatest</item> <!-- darker variant status bar , contextual app bars --> <item name="colorprimarydark">@color/redlatest_dark</item> <item name="coloraccent">@color/redlatest</item> <item name="actionbarstyle">@style/myactionbar</item> <item name="actiondropdownstyle">@style/myactionbardropdown</item> </style>
now when run above code don't action bar in activity fine, toolbar not showing wierd. know might doing silly mistake not able find out.please help
you have added view in relativelayout
, hence should specify have positioned. since have not specified tablayout
tablayout
overlapping toolbar
. add android:layout_below="@id/toolbar"
in tablayout
.
<android.support.design.widget.tablayout android:id="@+id/tabs" android:layout_below="@id/toolbar" android:layout_width="match_parent" android:layout_height="48dip" android:background="@drawable/background_tabs" />
Comments
Post a Comment