I am learning android dev and my question might be very simple. I am stuck at the below part and requesting your help
Description
I am using the android's default "Navigation Drawer" activity to implement a small project. I have created a fragment and when user selects an option from Navigation drawer, the fragment opens.
Problem faced
When the fragment opens, part of the fragment & action bar is clipped. Image below
Code
fragment layout
<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:fitsSystemWindows="true"
android:clipToPadding="false"
android:orientation="vertical"
android:background="#ffffff"
android:layout_weight="120"
tools:context="test.navigationdrawcheck.RateCalculator">
<EditText
android:layout_width="wrap_content"
android:layout_height="5dp"
android:inputType="number"
android:ems="12"
android:gravity="center"
android:layout_weight="10"
android:hint="text 1"
android:textColorHint="@color/colorDivider"
android:id="@+id/editText"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="5dp"
android:inputType="number"
android:hint="text 2"
android:textColorHint="@color/colorDivider"
android:ems="12"
android:gravity="center"
android:layout_weight="10"
android:id="@+id/editText1"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="5dp"
android:inputType="number"
android:hint="text 3"
android:textColorHint="@color/colorDivider"
android:ems="12"
android:gravity="center"
android:layout_weight="10"
android:id="@+id/editText3"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="wrap_content"
android:layout_height="5dp"
android:inputType="number"
android:hint="text 4"
android:textColorHint="@color/colorDivider"
android:ems="12"
android:gravity="center"
android:layout_weight="10"
android:id="@+id/editText4"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Total "
android:textColor="@color/colorDivider"
android:layout_weight="10"
android:textStyle="bold"
android:gravity="center_vertical"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
/>
<Button
android:layout_width="match_parent"
android:layout_height="10dp"
android:inputType="number"
android:ems="15"
android:gravity="center"
android:layout_weight="5"
android:id="@+id/editText6"
android:text="Submit"
android:textSize="20sp"
android:textColor="@color/colorWhite"
android:background="@color/colorPrimary"
android:layout_gravity="center_horizontal" />
App Bar Code
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="test.navigationdrawcheck.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:elevation="4dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/framecheck"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Actual output i am looking for
Below is my actual fragment layout xml. When i merge it with Navigation drawer it should not be clipped and fragment items should be displayed correctly
What I have tried so far
I tried adding this android:windowActionBarOverlay=false
in my styles.xml but no luck
Requesting your suggestions
How do we hide the menu on toolbar in one fragment? When you click the show button to open a fragment, you can see the fragment menu items ordered before activity menu items. This is because of the menu item's android:orderInCategory attribute value. When you click the hide button to hide the fragment.
A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.
In Android applications, ActionBar is the element present at the top of the activity screen.
Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button. In general an ActionBar consists of the following four components: App Icon: App branding logo or icon will be displayed here.
use FrameLayout
instead of LinearLayout
and add this to your FrameLayout
of the fragment
android:layout_marginTop="?attr/actionBarSize"
at leaset worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With