I can't scroll my webview after adding navigation drawer
Can you give me solution? I'm stuck here!
here's the code:
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
thanks for your help!!
Related
I'm trying to implement a navigation drawer into my app, but for some reason whenever I add the nav drawer fragment in my main_activity xml layout, it covers up/replaces the content of my main activity. When I remove the fragment, my recyclerview properly appears again.
activity_main.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:fitsSystemWindows="true"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include android:id="#+id/toolbar_actionbar"
layout="#layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout android:id="#+id/container"
android:layout_width="match_parent"
android:clickable="true" android:layout_height="match_parent"
android:layout_below="#id/toolbar_actionbar">
<android.support.v7.widget.RecyclerView
android:id="#+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/fab_image_button"
android:layout_width="#dimen/fab_button_diameter"
android:layout_height="#dimen/fab_button_diameter"
android:background="#drawable/btn_order_hub"
android:src="#drawable/btn_order_hub_trans"
android:layout_above="#+id/space2"
android:layout_alignStart="#+id/space2"
android:tint="#android:color/white"
android:elevation="#dimen/elevation_high"
android:stateListAnimator="#anim/button_elevation"/>
<Space
android:layout_width="#dimen/fab_button_diameter"
android:layout_height="#dimen/fab_button_margin_bottom"
android:layout_alignParentBottom="true"
android:layout_toStartOf="#+id/space"
android:id="#+id/space2" />
<Space
android:layout_width="#dimen/fab_button_margin_right"
android:layout_height="#dimen/fab_button_diameter"
android:layout_gravity="left|top"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/space" />
</RelativeLayout>
<fragment android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width" android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.android.expresso.expresso.NavigationDrawerFragment"
tools:layout="#layout/fragment_navigation_drawer" />
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
fragment_navigation_drawer.xml
<ListView 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:choiceMode="singleChoice"
android:divider="#android:color/transparent" android:dividerHeight="0dp"
android:background="#cccc"
tools:context="com.android.expresso.expresso.NavigationDrawerFragment" />
And this is what happens when I run the app. Note: the Matthew Steinhardt and Matthew.steinhardt#gmail.com is the text that's supposed to only show up when the navigation drawer is opened, but for some reason it's also showing up in my main activity.
Left - Image of the problem, Right, Image of the nav drawer:
If you need any more info, lemme know, and thanks!
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="240dp"
android:layout_height="match_parent" android:choiceMode="singleChoice"
android:divider="#android:color/transparent" android:dividerHeight="0dp"
android:background="#cccc"
tools:context="com.android.expresso.expresso.NavigationDrawerFragment" />
</android.support.v4.widget.DrawerLayout>
Hope this will Help you.
I'm working on an android-app, and I want that the Webview shows up if the Javascript was applied.
But now the WebView is only shown after I pull out the Menu.
MainActivity.java
http://pastebin.com/Kj4Nbqs9
WebViewFragment.java
http://pastebin.com/0kPSub3c
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView
android:id="#+id/drawer_list"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
fragment_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
I am using a custom list view to display data in my app, Then i tried to add navigation drawer
Clicks on drawer layout doesnt work. It end up opening the custom list view as it is behind the drawer list view. Drawer list view never gets focus, Even when the drawer is opened
Below is my main activity xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:focusable="true"/>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:focusableInTouchMode="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants"/>
</android.support.v4.widget.DrawerLayout>
<ListView
android:id="#+id/listScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="7dp">
</ListView>
</RelativeLayout>
Use this way :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/actionbar" />
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<include layout="#layout/activity_main" />
<!-- The navigation drawer -->
<include layout="#layout/drawer_layout_right" />
<include layout="#layout/drawer_layout_left" />
</android.support.v4.widget.DrawerLayout>
drawer_layout_right.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:orientation="horizontal" >
<ListView
android:id="#+id/lv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
drawer_layout_left.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:orientation="vertical" >
<ListView
android:id="#+id/lv2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" />
</LinearLayout>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="#layout/activity_main" />
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:focusable="true"/>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>
I am using Navigation Drawer Pager Sliding Tab Strip. It is showing menus in Slider. Now, I want to add Profile Photo and User Name in Slider. I have tried adding LinearLayout but It is giving ClassCastException.
Source : https://github.com/Balaji-K13/Navigation-drawer-page-sliding-tab-strip
activity.xml :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
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/content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/lightish"
android:choiceMode="singleChoice"
android:divider="#color/blue"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
Use this layout and you'll get what you need.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="#+id/frameContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- Left drawer -->
<LinearLayout
android:id="#+id/leftDrawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:gravity="center" >
<ImageView
android:id="#+id/imgProfilePic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/user_placeholder_88"
android:contentDescription="#string/profile_pic" />
<TextView
android:id="#+id/lblUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Medium" />
<ListView
android:id="#+id/drawerList"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#color/drawerListDivider"
android:dividerHeight="0dp"
android:listSelector="#drawable/drawer_list_selector"
android:background="#color/drawerListBackground"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Hello i have such layout and i don`t understand how to add static header with photo and text
to Navigation Drawler. Any example? Thanks
like this one
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#9d9d9d"
android:dividerHeight="1dp"
android:background="#252525" />
It's actually not as simple as user665 suggests. If you're going straight off the example provided by Google, you need to let the DrawerLayout know what its content is by changing DrawerLayout.isDrawerOpen and DrawerLayout.closeDrawer to the View your ListView is wrapped in, otherwise you're going to throw a ClassCastException because the LayoutParams won't match up.
So, to make a static header, you could do somehting like:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/drawer_content"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical" >
<ImageView
android:id="#android:id/icon"
android:layout_width="match_parent"
android:layout_height="200dp"
android:contentDescription="#null"
android:scaleType="centerCrop" />
<ListView
android:id="#+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Then reference R.id.drawer_content when using the methods I listed above.
After the FrameLayout, the first view will accepted as Navigation Drawer, so you create a layout after FrameLayout, then put your Views inside of it. Here is a example, it is very basic but you will get the point.
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_height="match_parent"
android:layout_width="320dp"
android:orientation="vertical"
android:layout_gravity="start" >
<RelativeLayout
android:id="#+id/NavDrawerInfo"
android:layout_width="320dp"
android:background="#drawable/bg"
android:layout_height="100dp">
<ImageView android:src="#drawable/ic_launcher"
android:id="#+id/userImage"
android:layout_width="200dp"
android:layout_marginRight="200dp"
android:layout_height="100dp"/>
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginLeft="125dp"
android:textSize="20sp"
/>
<TextView
android:id="#+id/userImage"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="125dp"
android:textSize="20sp"
/>
</RelativeLayout>
<ExpandableListView android:id="#+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#color/list_divider"
android:childDivider="#color/list_divider"
android:groupIndicator="#drawable/group_indicator"
android:dividerHeight="2dp"
android:gravity="start"
android:background="#f1f1f1"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>