Fragment Navigation Drawer Initializes as Open - android

I am trying to create a Navigation Drawer (it's outdated I know) with a custom layout. I am using a fragment within the NavDrawer to accomplish this.
The problem I am having is that when I run my app, my navigation drawer is automatically opening and I have no way to close it / no idea how. I suspect it has to do with the .commit() method at the end of my fragment transaction.
So my question is how do I get the nav drawer, housing a fragment, to operate like a normal nav drawer that only contains a ListView where it can be dragged in and out? Or if a fragment causes too many difficulties in a nav drawer is there another way for a super custom layout inside of a nav drawer? Thanks in advance!
Here is what it looks like. Code is below picture...
in MapsActivity.java:
//Instantiates Fragment inside of our Nav Drawer
NavigationDrawerFragment navDrawerFragment = new NavigationDrawerFragment();
getFragmentManager().beginTransaction()
.add(R.id.navDrawer_container,
navDrawerFragment).addToBackStack(null).commit();
activity_maps.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"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorMapToolbar"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
<!-- contentInsert is the initial padding that is added by the system at the start -->
<RelativeLayout
android:id="#+id/topLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageView
android:id="#+id/back_action"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="6dp"
android:layout_marginStart="6dp"
android:gravity="center_vertical"
android:padding="6dp"
android:src="#drawable/icon_goleft" />
<ImageView
android:id="#+id/locker"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:gravity="center_vertical"
android:padding="6dp"
android:src="#drawable/lock_open" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<View
android:id="#+id/dropshadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginTop="?attr/actionBarSize"
android:background="#drawable/dropshadow_dark" />
<ImageButton
android:id="#+id/floatingActionImageButton"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="15dp"
android:background="#drawable/circle"
android:focusable="true"
android:src="#drawable/icon_location" />
<LinearLayout
android:id="#+id/markerLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="#color/colorMapToolbar"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:id="#+id/markerCancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="#string/cancel"
android:textColor="#android:color/white"
android:textSize="#dimen/abc_text_size_large_material" />
<TextView
android:id="#+id/markerMark"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="#string/mark"
android:textColor="#color/colorAccent"
android:textSize="#dimen/abc_text_size_large_material"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<!-- FRAGMENT CONTAINER -->
<FrameLayout
android:id="#+id/navDrawer_container"
android:layout_width="240dp"
android:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>
fragment_navigation_drawer.xml: (accompanied by a .java for Fragment but it is not relevant here)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="200dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2"
android:background="#android:color/white">
<RelativeLayout
android:id="#+id/topRowLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="8dp">
<TextView
android:id="#+id/userTitleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:padding="8dp"
android:text="#string/userTitle"
android:textStyle="bold" />
<TextView
android:id="#+id/alertTitleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="8dp"
android:text="#string/alertTitle"
android:textStyle="bold" />
<TextView android:id="#+id/lastFlamText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="center_horizontal"
android:text="#string/lastFlameTitle"
android:layout_below="#+id/userTitleBtn" />
<TextView
android:id="#+id/scoreTextNavDrawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal|bottom"
android:padding="16dp"
android:textSize="100sp"
android:textStyle="bold"
android:layout_below="#+id/lastFlamText" />
</RelativeLayout>
<ListView
android:id="#+id/navList"
android:layout_width="240dp"
android:layout_height="0dp"
android:layout_gravity="left|start"
android:layout_weight="1" />
</LinearLayout>

The android:layout_gravity="left|start" attribute needs to go on the navDrawer_container FrameLayout in the activity_maps layout. This attribute lets the DrawerLayout know that this View is the drawer. The fact that it's missing would explain why your drawer is "open" on startup, and immovable.
<FrameLayout
android:id="#+id/navDrawer_container"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start" />
You don't necessarily need that attribute now on the ListView in the fragment_navigation_drawer layout.

Add this Code in your activity or Fragment
#Override
public void onStart() {
super.onStart();
if (drawer_layout.isDrawerOpen(Gravity.LEFT)) {
drawer_layout.closeDrawer(Gravity.LEFT);
}
}

Related

How to add two Button in Navigation Drawer and on each Button show Different Menu Items

Please help me to make a navigation drawer with two menus and two different button to inflate the each Menu Items and click listener
Below is the Mock up and I want to make drawer like these
Navigation Drawer First Button View
Navigation Drawer Second Button View
Please check this, it will help to add a custom view. You can use tablayout and view pager
I have read your question very carefully and try to make this layout. Finally i make it .
try this code to achieve your layout
activity_home_navigation_activtiy
<?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/app_bar_home_navigation_activtiy"
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--<include layout="#layout/nav_header_home_navigation" />-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".28"
android:background="#color/colorPrimary"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingBottom="15dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/navigation_user_img"
android:layout_width="65dp"
android:layout_height="65dp"
android:src="#drawable/ic_launcher_foreground" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/navigation_user_name_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Picks App"
android:textColor="#504C4C"
android:textSize="17dp"
android:textStyle="italic" />
<TextView
android:id="#+id/navigation_user_email_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Last Name"
android:textColor="#000"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/navigation_nested"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".72"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<Button
android:id="#+id/usr_bt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="User"/>
<Button
android:id="#+id/admin_bt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:text="Admin"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/user_recyler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:paddingLeft="15dp"
android:scrollbars="none" />
<android.support.v7.widget.RecyclerView
android:id="#+id/admin_recyler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:paddingLeft="15dp"
android:scrollbars="none" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
In this layout i try to make custom drawable . you can also customize according to your need
see screen shot
Thank You

ScrollView inside a NavigationDrawer menu

I want to implement ScrollView in NavigationDrawer template of Android Studio. What do I need to do? How can make the full Navigation menu scrollable? I have a lot of options are here, but I can't scroll & view all of them
Demo Image
I am using for this including layout in navigationView which I can easily manage.
Like this
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginEnd="-65dp"
android:layout_marginRight="-65dp"
android:fitsSystemWindows="true">
<include
layout="#layout/nav_header_main_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
nav_header_main_navigation
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/app_gray"
android:gravity="bottom">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rlTop"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_alignParentTop="true"
android:background="#color/appYellow">
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="24dp"
android:layout_marginEnd="30dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="30dp"
android:layout_marginStart="24dp"
android:ellipsize="end"
android:includeFontPadding="false"
android:maxEms="14"
android:maxLines="2"
android:textColor="#color/app_gray"
android:textSize="15sp" />
<RelativeLayout
android:id="#+id/rlBack"
android:layout_width="30dp"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="20dp"
android:clickable="true">
<ImageView
android:id="#+id/ivBack"
android:layout_width="10dp"
android:layout_height="20dp"
android:adjustViewBounds="true"
android:clickable="true"
android:scaleType="centerCrop"
android:src="#drawable/back_icon_black" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlBottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/rlTop"
android:background="#color/app_gray">
<RelativeLayout
android:id="#+id/rlProfile"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="10dp">
<ImageView
android:id="#+id/ivProfile"
android:layout_width="19dp"
android:layout_height="19dp"
android:layout_centerVertical="true"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:src="#drawable/icon_nav_profile" />
<TextView
android:id="#+id/tvProfile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_toEndOf="#id/ivProfile"
android:layout_toRightOf="#id/ivProfile"
android:includeFontPadding="false"
android:paddingBottom="1dp"
android:paddingTop="1dp"
android:text="#string/profile"
android:textAlignment="viewStart"
android:textColor="#color/white"
android:textDirection="locale"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Here is my whole Navigation activity XML
<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/app_bar_main_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginEnd="-65dp"
android:layout_marginRight="-65dp"
android:fitsSystemWindows="true">
<include
layout="#layout/nav_header_main_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Here is a major factor to avoid ViewPager
app_bar_main_navigation
<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:background="#color/app_gray"
tools:context="com.barq.consumer.ui.home.MainNavigationActivity">
<FrameLayout
android:id="#+id/flMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Now in MainNavigationActivity.Java
public class MainNavigationActivity extends BaseActivity {
#BindView(R.id.drawer_layout)
DrawerLayout drawer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_navigation);
ButterKnife.bind(this);
//here is you can load your fragment without view pager
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.flMain, HomeFragment.newInstance(), HomeFragment.TAG)
.commit();
}
And other clicks you can handle manually to load other fragments in frame layout and activities and drawer open and close you also handle manually use drawer object. Hope so you can understand it.
its an example for your easiness to avoid menu and use normal layouts in the scroll view.
Here are more answers regarding the above example ULR

Toolbar turns darker than normal while opening drawer

While I open the drawer the toolbar's colors turns way more darker than the color of the rest of the screen.
Initially Toolbar's background color is white. Any ideas why this is happening ?
The code I'm using is below :
<android.support.v4.widget.DrawerLayout
android:id="#+id/dl_poll_container"
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:background="#color/white"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="false">
<LinearLayout android:id="#+id/ll_toolbar_container"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar android:id="#+id/tb_poll_toolbar"
android:gravity="center"
android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_poll_toolbar_title"
android:gravity="center" android:layout_gravity="center"
android:textSize="#dimen/text_size_xxxlarge" android:fontFamily="sans-serif"
android:textColor="#color/black" tools:text="My Title"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</LinearLayout>
<FrameLayout android:background="#color/white"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent" android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="#+id/vp_poll_viewpager"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_gravity="center_horizontal"
android:layout_marginTop="48dp"
android:background="#drawable/background_line"
android:layout_width="144dp" android:layout_height="wrap_content">
<FrameLayout android:layout_width="36dp" android:layout_height="36dp"
android:layout_alignParentLeft="true">
<ImageView
android:id="#+id/pager_img_one"
android:layout_width="36dp" android:layout_height="36dp"
android:scaleType="centerInside"
app:srcCompat="#drawable/ic_active_nav" />
<TextView android:id="#+id/tv_poll_one"
android:textStyle="bold"
android:text="1" android:gravity="center"
android:textColor="#color/white"
android:layout_width="36dp" android:layout_height="36dp" />
</FrameLayout>
<FrameLayout android:layout_width="36dp" android:layout_height="36dp"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/pager_img_two"
android:layout_width="36dp" android:layout_height="36dp"
android:scaleType="centerInside"
app:srcCompat="#drawable/ic_deactive_nav" />
<TextView android:id="#+id/tv_poll_two"
android:visibility="invisible" android:textStyle="bold"
android:text="2" android:gravity="center"
android:textColor="#color/white"
android:layout_width="36dp" android:layout_height="36dp" />
</FrameLayout>
<FrameLayout android:layout_width="36dp" android:layout_height="36dp"
android:layout_alignParentRight="true">
<ImageView
android:id="#+id/pager_img_three"
android:layout_width="36dp" android:layout_height="36dp"
android:scaleType="centerInside"
app:srcCompat="#drawable/ic_deactive_nav" />
<TextView android:id="#+id/tv_poll_three"
android:visibility="invisible" android:textStyle="bold"
android:text="3" android:gravity="center"
android:textColor="#color/white"
android:layout_width="36dp" android:layout_height="36dp" />
</FrameLayout>
</RelativeLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/pb_container"
android:layout_width="match_parent" android:layout_height="8dp"
android:background="#android:color/transparent"
android:gravity="bottom">
<ProgressBar android:id="#+id/progress_bar"
style="#style/Widget.AppCompat.ProgressBar.Horizontal"
android:progressDrawable="#drawable/progress_bar_drawable"
android:indeterminate="false"
android:max="100" android:progress="0"
android:layout_width="match_parent" android:layout_height="8dp" />
</LinearLayout>
<TextView android:text="Uploading Video Progress"
android:textColor="#color/app_body_text_3" android:gravity="center_horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nv_poll_navigation"
android:background="#color/white"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:fitsSystemWindows="false" android:layout_gravity="start" />
DrawerLayout should have two children: the main content view and the navigation drawer.
https://developer.android.com/training/implementing-navigation/nav-drawer.html#DrawerLayout
So you should wrap the main content with FrameLayout like this:
<android.support.v4.widget.DrawerLayout
android:id="#+id/dl_poll_container"
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:background="#color/white"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="false">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/ll_toolbar_container"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="wrap_content">
...
</LinearLayout>
<FrameLayout android:background="#color/white"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent" android:layout_height="wrap_content">
....
</FrameLayout>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nv_poll_navigation"
android:background="#color/white"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:fitsSystemWindows="false" android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>
There is a method in the DrawerLayout named setScrimColor with a default value (some kind of transparent dark grey).
You can use that method to change the color that is drawn on top of the content when the drawer is opened. You can set it to fully transparent if needed

Android-Bottom sheet does not expand

So basically,i'm using the bottom sheet view from the support library. It opens up after a FAB is pressed.
This is the bottom sheet view file:
<LinearLayout
android:id="#+id/bottomSheetView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/bottom_sheet_behavior"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="150dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="New"
android:id="#+id/newLabel"
android:layout_gravity="center_horizontal" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="#+id/newLabel"
android:background="#c0c0c0"/>
<Button
android:id="#+id/newFileButton"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="File"
android:layout_gravity="center_horizontal"
/>
<Button
android:id="#+id/newFolderButton"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Folder"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
and this is the main activity layout:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/coordinator"
>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- The first child in the layout is for the main Activity UI-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
tools:context=".MainActivity"
android:background="#ffffffff"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/cwdLabel" />
<!--view that creates a dividing line between listview and textview -->
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_below="#+id/cwdLabel"
android:background="#c0c0c0"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/fileList"
android:layout_below="#+id/cwdLabel"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:borderWidth="0dp"
app:backgroundTint="#color/colorAccent"
app:elevation="6dp"
android:clickable="true"
app:fabSize="normal"
app:pressedTranslationZ="12dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/ic_add_white_18dp"
/>
</RelativeLayout>
<!-- Side navigation drawer UI -->
<ListView
android:id="#+id/navList"
android:layout_width="275dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#ffeeeeee"
/>
</android.support.v4.widget.DrawerLayout>
<include layout="#layout/bottom_sheet_new"/>
</android.support.design.widget.CoordinatorLayout>
The problem is, that the bottom sheet doesn't open when you press the FAB.
Instead, it opens after you slide the drawer out.Also, the bottom sheet is transparent, which is not what i have set it to be.
I searched around for answers, and after reading a few other questions, i think it has to do with the elevation of the drawer layout, but i don't really know how to solve that problem
I had the same issue, I updated the com.android.support:appcompat to the last version and now it works!
Nowadays I have
'com.android.support:appcompat-v7:23.4.0'
'com.android.support:design:23.2.0'
Try this,
Put this after initilizing views
ViewCompat.postOnAnimation(coordinator, new Runnable() {
#Override
public void run() {
ViewCompat.postInvalidateOnAnimation(coordinator);
}
});
Hope it helps

Layout problems, cannot interact with map

I need some help with a layout. I have a map, a drawer, a button for the drawer and a cardview to hold the autocomplete search box. Everything looks fine except i cannot interact with the map. Pinch zoom, swipe to move and My Location button are not working. I think it's because the layout is wrong and i'm not actually interacting with the map but with something else. Posting my layout below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
map:uiZoomControls="true"
map:uiZoomGestures="true"
map:mapType="normal"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MapsActivity">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/LeftDrawer"
android:layout_width="200dp"
android:layout_marginTop="60dp"
android:layout_height="500dp"
android:layout_gravity="start"
android:background="#drawable/layout_bg" >
<TextView
android:id="#+id/TitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textColor="#android:color/darker_gray"
android:text="Test Title" />
<ListView
android:id="#+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_gravity="left|start"
android:background="#drawable/layout_bg"/>
<TextView
android:id="#+id/TitleTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:textColor="#android:color/darker_gray"
android:text="Test Title 2" />
<Button
android:id="#+id/test_button1"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="20dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="#drawable/settings"/>
<Button
android:id="#+id/test_button2"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="60dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="#drawable/settings"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="top"
android:layout_marginTop="17dp"
android:layout_marginLeft="50dp"
android:layout_width="260dp"
android:layout_height="30dp"
card_view:cardCornerRadius="4dp">
<fragment
android:id="#+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
</android.support.v7.widget.CardView>
<Button
android:id="#+id/drawer_button"
android:layout_width="30dp"
android:layout_marginTop="17dp"
android:layout_marginLeft="5dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:onClick="OpenCloseDrawer"
android:background="#drawable/settings"/>
</fragment>
</LinearLayout>
Edit: Posting a screenshot of what the app looks like. Top left button is the open/close drawer button. As seen in the screen shot, that button (#+id/drawer_button) becomes inaccessable. The drawer closes when touching outside, but i have code in that button that then never fires as the button is not accessable. So i would like to always have access to the button, as well as probably some way of detecting the drawer closing, so i can use the same code in that event as i do in my button in case the user just swipes/touches outside to close the drawer.
Here are my layouts as the are now.
activity_maps.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="#+id/map" layout="#layout/fragment" />
<RelativeLayout
android:id="#+id/whatYouWantInLeftDrawer"
android:layout_width="200dp"
android:layout_marginTop="60dp"
android:layout_height="500dp"
android:layout_gravity="start"
android:background="#drawable/layout_bg" >
<TextView
android:id="#+id/TitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textColor="#android:color/darker_gray"
android:text="Title1" />
<ListView
android:id="#+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_gravity="left|start"
android:background="#drawable/layout_bg"/>
<TextView
android:id="#+id/TitleTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:textColor="#android:color/darker_gray"
android:text="Ttitle2" />
<Button
android:id="#+id/test_button1"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="20dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="#drawable/settings"/>
<Button
android:id="#+id/test_button2"
android:layout_width="30dp"
android:layout_marginTop="270dp"
android:layout_marginLeft="60dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:background="#drawable/settings"/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
fragment.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
map:uiZoomControls="true"
map:uiZoomGestures="true"
map:mapType="normal"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MapsActivity">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/drawer_button"
android:layout_width="30dp"
android:layout_marginTop="17dp"
android:layout_marginLeft="5dp"
android:layout_height="30dp"
android:layout_gravity="left|start"
android:onClick="OpenCloseDrawer"
android:background="#drawable/settings"/>
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="top"
android:layout_marginTop="17dp"
android:layout_marginLeft="50dp"
android:layout_width="240dp"
android:layout_height="30dp"
card_view:cardCornerRadius="4dp">
<fragment
android:id="#+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />
</android.support.v7.widget.CardView>
</fragment>
</FrameLayout>
</LinearLayout>
what you need to understand is that your will have only two child like this
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
< first View, here you will have your google map/>
< second View, here you will have your ListView/>
</android.support.v4.widget.DrawerLayout>
now the problem is that you don't just have a plain google map to show as First View, what you can do is create a separate fragment which will replace your first view,
There are many ways to do this depending on what you want to achieve with it, it will work fine as long as you keep this pattern for DrawerLayout
well to make it simple create fragment which will have google map and your cardview
fragment.xml
<LinearLayout>
<FrameLayout>
<GoogleMapFragment
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<CardView
android:layout_width="280dp"
android:layout_height="?attr/actionBarSize"/>
</FrameLayout>
</LinearLayout>
now make some changes to your Navigation drawer layout like this
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<first View, include fragment & class representing that stuff/>
< second View, here you will have your ListView/>
</android.support.v4.widget.DrawerLayout>
this is just an example that you make implement your own layout:
Update
<FrameLayout>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<first View, include fragment & class representing that stuff/>
< second View, here you will have your ListView
margin="leave enough margin to top as you will have buttons, otherwise button will overlap listview"
/>
</android.support.v4.widget.DrawerLayout>
<LinearLayout>
<put your button Views here, so these will appear all the time/>
</LinearLayout>
</FrameLayout>

Categories

Resources