Can not find navigation drawer layout in android studio - android

When building my application I selected the template with the navigation drawer. Now however I can't access the drawer to edit from the design tab in android studio.
Image of Template I chose for refrence
Is their something in I need to do in the XML (below) to make it view able again?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="56dp"
tools:showIn="#layout/app_bar_main"
tools:visibility="visible">
<ImageButton
android:id="#+id/inactiveButton"
android:layout_width="346dp"
android:layout_height="346dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.489"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498"
app:srcCompat="#drawable/button_pressed" />
EDIT: squished view

Related

How can I make a Navigation Drawer go to the back of the Layout when Closed?

In my layout xml file i have a webView and a Navigation Drawer:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</WebView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/boReFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:contentDescription="#string/add_to_bookmarks"
android:focusable="true"
android:translationY="-480px"
android:visibility="gone"
app:backgroundTint="#03A9F4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#android:drawable/btn_star_big_off"
tools:ignore="SpeakableTextPresentCheck,ImageContrastCheck" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/baHoFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:contentDescription="#string/go_back_home"
android:focusable="true"
android:translationY="-320px"
android:visibility="gone"
app:backgroundTint="#E91E63"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#android:drawable/ic_menu_gallery"
tools:ignore="SpeakableTextPresentCheck" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/shLiFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:contentDescription="#string/go_to_the_shopping_list"
android:focusable="true"
android:translationY="-160px"
android:visibility="gone"
app:backgroundTint="#E91E63"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#drawable/baseline_view_list_24"
tools:ignore="SpeakableTextPresentCheck" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/moBuFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:contentDescription="#string/show_buttons"
android:focusable="true"
app:backgroundTint="#E91E63"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="#android:drawable/ic_menu_add"
tools:ignore="SpeakableTextPresentCheck" />
<androidx.drawerlayout.widget.DrawerLayout
android:id="#+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="HardcodedText,SpeakableTextPresentCheck">
<!--this the navigation view which draws
and shows the navigation drawer-->
<!--include the menu created in the menu folder-->
<com.google.android.material.navigation.NavigationView
android:id="#+id/navView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/navigation_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
When I run this, I can't click on the webview at all. But if i switch the order of the webview and the navigation drawer, then i can press on the webview but i cannot open the navigation drawer (or it can't be seen). I want to be able to click and open both. How can i achieve this functionality?
A typical pattern to achieve the overall goals you want here is to use a Toolbar and a hamburger icon to trigger open/close of the NavDrawer.
Without that, using your current approach, you could:
setup a Guideline within the ConstraintLayout,
have the WebView start from that guideline and end at the parent,
set the WebView width to 0dp to allow the Constraints to control the width.
https://developer.android.com/reference/androidx/constraintlayout/widget/Guideline

Android App : White space in the top screen

White blank space in the android app. YELLOW highlighted area
XML as below:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.CustomerFragment">
<SearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="#color/black_overlay"
app:layout_constraintBottom_toTopOf="#+id/customer_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/customer_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:paddingBottom="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/search_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
I tried to change few things, but in the constraint layout, I couldn't remove that white space
EDIT-1
See the full screen image, in the bottom I have the three panel that hold three button for my application tabs

Android Studio - ImageView no preview in .xml file

I have an ImageView in my activity that is visible when I run the app.
But it is not visible in the preview in the Design view of the activity_main.xml.
How do I make it show?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
...
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Hello World!"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<ImageView
android:id="#+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="#+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#drawable/ic_baseline_arrow_upward_24"
tools:ignore="ContentDescription"/>
</androidx.constraintlayout.widget.ConstraintLayout>
It does not matter wether it is a .png that I put in drawables or a symbol I take from Android Studio.
If you are using AppCompatActivity app:srcCompat="#drawable/ic_baseline_arrow_upward_24"
if you are using Activity android:src="#drawable/ic_baseline_arrow_upward_24"

How to make View in a ConstraintLayout fill the available height?

I'm new to Android development. I created an activity/layout with two views. The first one is a custom button that I want to be 50dp high. The second is a list view that I want to take the rest of the screen below it.
My problem is that when I constrain them to each other, the ListView gets crushed to 0 and the "springs" around the 50dp button expand to take all the space. Here I've given the list a height of 200dp so you can see it. If I set it to "match constraint" it goes to 0. There is content in the list.
With iOS constraints I know how to do this. The constraints around the button are behaving like "greater than or equal" constraints in iOS. I want them to be "equal". How do you do this in Android?
Here's the XML.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
app:layout_constrainedHeight="false"
tools:context=".WorkoutActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/workout_list"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
You have to attach the top of listView to the bottom of playButton not other way around
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
app:layout_constrainedHeight="false"
tools:context=".WorkoutActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="8dp"
app:layout_constraintTop_toBottomOf="#id/play_pause_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Cheers :)
Since you want the ListView to occupy all of the available space, it is a good idea to set the height to 0dp. This is sorta like a stretch-me-how-you-like scheme for ConstraintLayouts. The height would therefore entirely depend on the top and bottom constraints. So, nice step!
Your mistake, however, was the way you constrained your views. You were supposed to constrain the ListView to the bottom of play_pause_button (as shown below). This way, the position of the ListView is always dependent on (and below) playButton.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
app:layout_constrainedHeight="false"
tools:context=".WorkoutActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="8dp"
app:layout_constraintTop_toBottomOf="#id/play_pause_button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I hope this helps. Merry coding!
Just set the constraints the right way. No constraint bottom in the button but a constraintTop in the listview.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
app:layout_constrainedHeight="false"
tools:context=".ui.MainActivity">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/play_pause_button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
this is working for me :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
app:layout_constrainedHeight="false">
<mycompany.PlayPauseButton
android:id="#+id/play_pause_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ListView
android:id="#+id/workout_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/play_pause_button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
With constraint layout, it's usually (at least in my experience) a lot easier to build either top-down or bottom-up, so get one component into a position where you're happy with it and then add then next one, maybe that helps

Fragments does not resize when the keyboard opens

I have an EditText which listens to click events on an activity and launches a fragment using fragmentTransaction.add(); both the activity and the fragment have a ConstraintLayout as a root ViewGroup. The fragment layout is as follows (Some elements has been omitted for brevity):
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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/fragment_CitySelection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="25dp"
android:background="#color/white"
android:clickable="true"
android:focusable="true"
tools:context=".CitySelectionFragment">
<EditText
android:id="#+id/city_AutoCompleteTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#layout/rounded_border_edittext"
android:hint="Ville"
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingTop="6dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:paddingBottom="10dp"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/back_ImageButton" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/cities_RecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/city_AutoCompleteTextView" />
</androidx.constraintlayout.widget.ConstraintLayout>
I tried adding android:windowSoftInputMode="adjustResize" in AndroidManifest and programmatically as of answers in some similar questions.
The problem is caused by some code I added to make the status bar completely transparent, which I found in this answer.
Adding android:fitsSystemWindows="true" to the fragment layout solved the problem.

Categories

Resources