Reputation: 95
In my program, I have this problem
The edit text stays on top of the toolbar but I want the edit text to stay below the toolbar like a normal layout.
I changed the activity theme to AppTheme.NoActionBar
because if I have normal AppTheme i cannot use the custom toolbar
activity_definicoes.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include layout="@layout/content_definicoes" />
<include
layout="@layout/app_bar_maps"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_maps"
app:menu="@menu/activity_maps_drawer" />
</android.support.v4.widget.DrawerLayout>
content_definicoes.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="number"
android:text="Raio"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
app_bar_maps.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/app_bar_maps"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.casimiro.pap.MapsActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</android.support.constraint.ConstraintLayout>
Upvotes: 0
Views: 50
Reputation: 324
You should not add more than two child inside android.support.v4.widget.DrawerLayout
You can do this,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include android:id="@+id/top"
layout="@layout/content_maps" />
<include
android:layout_below="@id/top"
layout="@layout/app_bar_maps"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
OR,
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/content_maps" />
<include
layout="@layout/app_bar_maps"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Upvotes: 1
Reputation: 2355
according to the documentation
To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity>. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
problem 1
you should only add your main content as the first child of the drawerLayout. here you have two childs
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/app_bar_maps"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include layout="@layout/content_maps" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_maps"
app:menu="@menu/activity_maps_drawer" />
</android.support.v4.widget.DrawerLayout>
Upvotes: 1
Reputation: 2211
Inside the DrawerLayout, add one view that contains the main content for the screen (your primary layout when the drawer is hidden) and another view that contains the contents of the navigation drawer.
There is more than that in your layout.
Change to it,
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/content_maps" />
<include
layout="@layout/app_bar_maps"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Upvotes: 1