ProgressBar isn't shown on one particular screen in Xiaomi - java

I have an application on android. In it I have a base activity with drawer and toolbar, this activity also contains progress bar and dimmed layout used by all the inheritors to display loading.
When I run the app on Xiaomi or Huawei phone (both Android 6.0.1), it works in all activities except one, and I can't figure out why. The dimmed layout is shown, but there's no progress bar. I tried to put progress bar into that activity, but it isn't shown anyway. When I run on emulator, everything's fine in all API's.
How it is:
How it should be (pay attention at the blue loading progress bar):
The layout of the base activity:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/view_toolbar"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
<include
android:id="#+id/left_drawer"
layout="#layout/view_drawer"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
<View android:id="#+id/dimmed_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:background="#android:color/black" />
<ProgressBar android:id="#+id/main_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"/>
</FrameLayout>
Activities-inheritors use progress bar and dimmed layout as following:
//Show loading:
mProgressBar.setVisibility(View.VISIBLE);
mDimmedBackground.setAlpha((float) 0.3);
//Hide loading:
mProgressBar.setVisibility(View.GONE);
mDimmedBackground.setAlpha((float) 0);
The activity where it doesn't work has the following layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="#dimen/view_padding_small"
android:scrollbars="vertical"/>
</FrameLayout>

Related

How to make my fragment fit between my toolbar and bottom navigation bar and still make it scrollable?

So I will have my main-activity layout file below so you can understand what is happening
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#menu/toolbar"/>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_nav">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_navigation"
app:itemIconTint="#android:color/white"
android:background="#39b54a"
app:labelVisibilityMode="unlabeled">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
The problem with this layout is that the toolbar on the top and the bottom navigation bar cover content from my fragments. Also one of my fragments has got a recyclerview with many items and I canĀ“t scroll down for some reason ? Is there a way to make the fragments fit exactly between the toolbar and bottomnavigation like resizing itself to fit into that area without cutting content and still make it scrollable ?
Do it like this ...
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_layout"/> <!--include your layout file here -->
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_below="#id/toolbar"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_nav">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_nav_menu"
app:itemIconTint="#android:color/white"
android:background="#39b54a"
app:labelVisibilityMode="unlabeled">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
And by the way, you are supposed to set a layout resource file into the toolbar layout while including but you are passing the menu resource file. Change that also accordingly...

What is a "Top-level destination" in android?

I am working in Android Studio using Java. I want to implement a Navigation Drawer(those left to right swipe ones) with a Hamburger icon always on top. But there is some issue of "Top-level destination" without which that Hamburger icon doesn't show up. One of the solutions I found was to make that activity as my Launcher activity but I don't want that.
Can someone please explain to me what this "Top-level destination" phrase means and a possible workaround for my Navigation Drawer problem!!
This is my navigation layout
<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:layout_width="match_parent"
android:id="#+id/drawer_layout"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:visibility="visible"
tools:context=".Main_Screen"
tools:openDrawer="start">
<include
layout="#layout/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/nav_view"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/drawer_menu"
app:headerLayout="#layout/drawer_header"
/>
</androidx.drawerlayout.widget.DrawerLayout>
this is the included appbar
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
style="#style/Widget.MaterialComponents.AppBarLayout.Primary">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:id="#+id/toolbar"
app:contentInsetStartWithNavigation="0dp" />
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
I have created an activity named LoginActivity, where I just put a button, and created an activity named MainActivity, where I put drawer. By clicking the button, I start the MainActivity.
In fact, I have not recurrented the problem you have said above.
But I have a suggestion that you may try creating the activity with drawer by file template not by hand, to avoid some mistakes that we have not discovered.
The step is: Right click the package name -> New -> Activity -> Navigation Drawer Activity.

layout_gravity= "start" is not working in Navigation View

layout_gravity attribute is not showing in Navigation View.I want to give the layout_gravity = "start" but it is not showing.
Here is my layout.xml file
<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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:elevation="#dimen/_4sdp"
android:background="#color/colorPrimary">
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
If you want to see your Navigation View you must add tools:openDrawer:"start" in the DrawerLayout.
This will set your Drawer as visible only in the layout editor, in the app it will be hidden until the user opens it.
Remember also to set the Gravity, the Menu and the Header Layout (if you have one) with
android:layout_gravity="start"
app:menu="#menu/your_menu"
app:headerLayout="#layout/your_header_layout"
in your NavigationView.
Hope it helps!
add this into drawer tools:openDrawer="start" and add this into navigation
android:layout_gravity="start"
and don't forget to add the menu app:menu="#menu/menu"
Just copy and past the below code and adjust it and it will work
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|left"
app:headerLayout="#layout/header"
app:menu="#menu/navigation_menu" />

DrawerLayout ListView not drawn with GLSurfaceView as content

My Android app is a fullscreen OpenGL ES 2.0 app, so the main content is a custom extension of GLSurfaceView.
The activity layout looks like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout">
<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="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111" />
</android.support.v4.widget.DrawerLayout>
I then add my GLSurfaceView using the addView method of the FrameLayout.
If i don't do this, the Drawer works as expected.
The ListView seems to be pulled out correctly when i swipe it in, as i can't interact with the GLSurfaceView anymore until i swipe it back to the left. But it's not displayed at all, like the GLSurfaceView is allways rendered ontop of it.
How do i get a DrawerLayout working with a GLSurfaceView as its content?
I've just faced the same problem, and I've found quite a silly workaround for it. This issue seems to only affect DrawerLayouts, and not regular Views. So simply place an empty View over your GLSurfaceView, to mask it away from the Drawer.
Here's my stripped down layout file as a sample for you:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<GLSurfaceView
android:id="#+id/glSurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<FrameLayout
android:id="#+id/frameLayoutDrawer"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#android:color/white" />
</android.support.v4.widget.DrawerLayout>

Fragment application, how to add a footer?

I'm working on an Android application with 4 tabs.
Here is my activity_main.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
And here is one of my tab (they are all the same for the moment)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff8400" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Top Screen"
android:textSize="20dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
How could I add a footer that would be visible on each tab?
It's to add a player that stays visible while scrolling the tab.
You're going to need to make a change to your main activity layout. You can do it with a LinearLayout or RelativeLayout. Because a LinearLayout is less expensive I will show you that here.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
<View
android:id="#+id/music_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
The view could been anything, I would recommend using a framelayout there and putting in a fragment if it is going to be as complicated as a music player. How this works is you set the height of the musicplayer (wrap_content) and you tell the pager to take up the rest of the space with layout_height="0dp" and layout_weight="1".
If you want to do a RelativeLayout then the musicplayer would alignParentBottom="true" and the pager would have layout_above="#+id/music_player with either layout_height="matchparent" or alignParentTop="true".

Categories

Resources