Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Part of Fragment items hides under Action bar

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 belowenter image description here

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

enter image description here

What I have tried so far

I tried adding this android:windowActionBarOverlay=false in my styles.xml but no luck

Requesting your suggestions

like image 572
Sriram Avatar asked Apr 16 '16 11:04

Sriram


People also ask

How do we hide the menu on toolbar in one fragment?

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.

What is a fragment a fragment is a part or portion of an activity a fragment is a single screen UI a fragment is used to move from one screen to another all of these?

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.

Where the action bar is present in the activity screen by default?

In Android applications, ActionBar is the element present at the top of the activity screen.

What is the action bar?

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.


1 Answers

use FrameLayout instead of LinearLayout and add this to your FrameLayout of the fragment

android:layout_marginTop="?attr/actionBarSize"

at leaset worked for me.

like image 58
Arash.Zandi Avatar answered Oct 01 '22 06:10

Arash.Zandi