Can I preview an open Navigation Drawer in Android Studio - android

I am making an app that will feature a Navigation Drawer. My computer cannot run the AVD emulator. Even with a minimal AVD, I have waited hours and it did not start up. That being said, I have had to rely on the Android Studio designer to see what the app will look like. When creating a Navigation Drawer activity, is there some way I can toggle it being open on the designer?

I found that you can add tools:openDrawer="start" to your DrawerLayout.
Like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="#+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:openDrawer="start">
<!-- your content include -->
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Demo:
not really perfect, but it's enough!

Related

Navigation View XML doesn't let me interact with anything else

I'm implementing a Navigation View on my activityHome for the first time. When i run the app and enter the home activity it function well. The problem is at the XML editor on the android studio, the Nav View is above all the other elements and doesn't let me click on them.
I haven't touch anything else but these yet.
Thanks.
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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/dl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:fitsSystemWindows="true"
tools:context=".activities.HomeActivity"
tools:openDrawer="start">
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/header"
android:background="#color/colorPrimary"
app:menu="#menu/menu"
tools:ignore="MissingConstraints" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/iv_menu"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?android:selectableItemBackground"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="#+id/guideline46"
app:layout_constraintEnd_toStartOf="#+id/guideline139"
app:layout_constraintStart_toStartOf="#+id/guideline135"
app:layout_constraintTop_toTopOf="#+id/guideline45"
android:elevation="10dp"
app:srcCompat="#drawable/menubuttonofthreelines_79781" />
...
and continues with the other elements.
Your layout has nothing wrong..
The reason that Android Studio shows that the drawer layout in the Open state in the design view because you set tools:openDrawer="start" in the DrawerLayout .. if you want to see the main layout in the design mode (i.e. to make the drawer in the close state), then you need to remove this attribute.
This attribute won't affect the looking of your app when you launch it.
Documentation:
You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.
XML tools namespace is just used to show you some behavior on Android Studio, but not while you run the app. Please check documentation for more info

iOS-like Navigation Drawer for Android?

I'm looking for a way to reproduce the navigation drawer of iOS on Android.
I can't figured out how to reproduce it.
The Navigation Drawer on iOS slide all the previous page and keep a little part of it on screen like this:
iOS like Navigation Drawer
Meanwhile the android Navigation Drawer goes over the previous page and hide it like this:
Android like Navigation Drawer
Is it just possible ?
Affirmative, it's very much possible in Android. Add the following in your build.gradle file:
dependencies {
implementation 'com.infideap.drawerbehavior:drawer-behavior:0.2.2'
}
Use android.support.design.widget.NavigationView inside your layout with com.infideap.drawerbehavior.AdvanceDrawerLayout to achieve this type of behavior like this:
<com.infideap.drawerbehavior.AdvanceDrawerLayout 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"
android:background="#color/colorWhite"
tools:openDrawer="start">
<include
layout="#layout/app_bar_default"
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"
android:background="#color/colorWhite"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</com.infideap.drawerbehavior.AdvanceDrawerLayout>
For more on the implementations & sample demos, please follow this link. Hope this helps!
iOS doesn't have a build-in Navigation Drawer component. The first link you provided contains a custom implementation. Best possible is to use third-party solution. For example, quite popular is SideMenu.

Android - WebViewFragment and NavigationBar

I'm making an app and I'm using fragments in an Activity, I'm switching this fragments with the replace function. The problem here is with the WebViewFragments, when replacing an existing WebViewFragment with other some times the system navigation bar becomes white...
App screens, from left to right: Normal, error, error:
This is my layout
Activity
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<include layout="#layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/contentPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:background="?colorAccent"
app:itemTextColor="#drawable/navigation_items_color_selector"
app:menu="#menu/menu_navigation"
style="#style/NavigationDrawerStyle"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
I'm using androids WebViewFragment so no layout there defined by me, I tried with a custom layout with the Webview as the root layout and got the same problem
The hierarchy viewer doesn't show anything abnormal
Left OK, Right Error:
On the equipment the navigation bar is showing white while on the hierarchy viewer it shows correctly, the letf image is without the problem, the right has the problem, no additional views.
I'm using gradle version 2.14.1 and the following support libs:
com.android.support:design:24.2.1
com.android.support:appcompat-v7:24.2.1
com.android.support:recyclerview-v7:24.2.1
com.android.support:cardview-v7:24.2.1
com.android.support:percent:24.2.1
Edit: forgot to mention, this happens on Android 7.0 and Android 6.0
This was caused by the webview using the layerType as LAYER_TYPE_HARDWARE, switching it to LAYER_TYPE_SOFTWARE resolved the issue

Using Scrolling Activity inside Navigation Activity

my primary goal is to have a navigation drawer with a Scrolling Activity while implementing material design so it would look something like a combination of these two:
Navigation Drawer Sample Image (Credits to Google)
Scrolling Activity Sample Image (Credits to Google)
As of right now I am doing this by associating a Navigation Drawer Layout's xml to my main activity and then including a Scrolling Layout's xml inside of Navigation Drawer Layout's content xml.
It's working after implementing many small changes in xmls of both the layouts but I don't feel like it's the optimal way to do so as it results in using more than 7 xmls at once for only one activity.
Does anybody know of a better way to do so?
You have to include scrolling layout into navigation layout.
<?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"
android:fitsSystemWindows="true">
<include layout="#layout/activity_scrolling"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"/>
</android.support.v4.widget.DrawerLayout>

How to make a Navigation Drawer with these functionalities in Android?

I want to implement an Android app which measures someone's performances in sport activities.
The problem which I have is that I must implement a sliding menu from the left side of the screen, where one can change the account on which the performances must be registered.
I don't know how to make the part which is show in this picture.
One can add a new user by clicking on add new user button, can edit the account by clicking on the pen, and switch to other account by clicking on it when it is inactive.
I've searched for info about how to do this but I didn't find anything related to this.
This is how my app must look:
Does anyone have an idea about how to do this or something similar to my issue?
You have to Go for Sliding menu lib.
you can use android DrawerLayout.
Please take look.
There is Suggestion of design for NavigationDrawer..............
This could help you to Create Layout like that...
First Create Navigation Drawer form Here : Creating a Navigation Drawer
and then change some code in Drawelayout.xml(which contains nav. drawer)
navDrawer.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/com.equest.cwely.act"
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" >
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/actionbar_bg"
android:orientation="vertical" >
<include
android:id="#+id/nav_list_header"
layout="#layout/nav_profile" />
<ListView
android:id="#+id/drawer_list"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="10dp"
android:choiceMode="singleChoice"
android:divider="#55ffffff"
android:dividerHeight="0.5dp"
android:listSelector="#drawable/list_selector" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Here,
<include/> : I have created one layout and added it into navDrawerLayout file...
<ListView/> : second Layout...........

Categories

Resources