android - Toolbar not visible in layout -
below layout, , when running toolbar not visible @ all, 2 tabs on tabview take entire screen. in preview in androidstudio see actionbar expect @ top. missing?
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/c"> <android.support.v7.widget.toolbar android:id="@+id/my_toolbar2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:background="?attr/colorprimary" android:layout_marginbottom="10dp" app:theme="@style/themeoverlay.appcompat.dark.actionbar" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" /> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/c2"> <android.support.design.widget.tablayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/tabs" app:layout_scrollflags="scroll|enteralways"/> </relativelayout> <android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.viewpager>
here activity using layout:
public class tabletgallery extends appcompatactivity implements actionbar.tablistener { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //to change body of overridden methods use file | settings | file templates. setcontentview(r.layout.tablet_gallery); // initilization toolbar = (toolbar) findviewbyid(r.id.my_toolbar2); setsupportactionbar(toolbar); viewpager = (viewpager) findviewbyid(r.id.pager); madapter = new tabspageradapter(getsupportfragmentmanager()); viewpager.setadapter(madapter); tablayout tablayout = (tablayout) findviewbyid(r.id.tabs); tablayout.setupwithviewpager(viewpager); tablayout.addtab(tablayout.newtab().settext("tab 1")); tablayout.addtab(tablayout.newtab().settext("tab 2"));
user linearlayout root layout instead.
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/c"> <android.support.v7.widget.toolbar android:id="@+id/my_toolbar2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:background="?attr/colorprimary" android:layout_marginbottom="10dp" app:theme="@style/themeoverlay.appcompat.dark.actionbar" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" /> <android.support.design.widget.tablayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/tabs" app:layout_scrollflags="scroll|enteralways"/> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/c2"> <android.support.v4.view.viewpager xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.viewpager> </relativelayout> </linearlayout>
Comments
Post a Comment