Issue
I've created a Toolbar
and added it on my main_activity.xml as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_detail"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/loginBrown"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:textColor="#fff"
android:textSize="16sp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:animateLayoutChanges="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
app:itemIconTint="@color/nav_item_state_list"
app:itemTextColor="@color/nav_item_state_list"
app:menu="@menu/bottom_navigation_items" />
</RelativeLayout>
Also changed the style.xml
to : <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
And in MainActivity
I've added this :
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar_detail);
setSupportActionBar(toolbar);
But even with this is not showing on the first Fragment
I do a fragment.replace()
to show the first Fragment
, and I do not know if that's the wrong thing
Solution
The FrameLayout in which the fragment loaded is on top of the ToolBar. That's why you can not see it. Add android:layout_marginTop="?android:attr/actionBarSize"
to the framelayout.
Answered By - Bertram Gilfoyle