While my application has been working fine on Android 4.3 - Android 6, on Android 7 the same design is not working anymore.
What should happen:
What actually happens on Nougat:
If the TextView has a margin of its height, it would show as expected on Nougat, however it wouldn't be on the bottom pre-Nougat.
This only occurs if this fragment is in a ViewPager. Otherwise it shows just fine.
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="48dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CONTENTS HERE"/>
</ScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:visibility="gone"
android:text="YOU CANNOT SEE ME"/>
</FrameLayout>
Note: It does not happen on Android Studio's design view, only on the real device. This screenshots are a replica of what happens on a real device.
Anyone has an idea?
Found a fix.
I was using
<android.support.v4.view.ViewPager
android:id="#+id/vpTabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:background="#android:color/white" />
By removing the layout behavior, it was fixed.
<android.support.v4.view.ViewPager
android:id="#+id/vpTabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" />
Related
I am creating a music app so i want to add bottom app bar in recyclerview, i tried but only Floating Action button is showing but bottomApp bar is not showing while testing on my phone, however its showing in android studio design preview, how can I fix it? what should i do?
here is xml code...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_height="match_parent"
android:background="#color/whito"
android:id="#+id/root_layout"
tools:context=".MusicActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="#color/black_dark"
android:background="#color/white"
app:fabCradleMargin="10dp"
app:fabAlignmentMode="end"
app:fabCradleRoundedCornerRadius="20dp"
app:fabCradleVerticalOffset="10dp"
app:menu="#menu/bottom_menu"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/black_dark"
app:layout_anchor="#id/bottom"
android:src="#drawable/menu"
android:contentDescription="#string/musicbites"
app:tint="#color/white"/>
<com.google.android.material.tabs.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/purple_200"
app:tabIndicatorColor="#color/white"
app:tabSelectedTextColor="#FF9800"
app:tabTextColor="#706E6E">
</com.google.android.material.tabs.TabLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/colorful"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" />
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-50dp"
android:layout_marginBottom="-674dp">
</androidx.viewpager2.widget.ViewPager2>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
BottomApp Bar is not showing in my phone while testing, but showing in android studio design preview, what should i do? How can I fix it?
BottomApp Bar is not showing in my phone while testing, but showing in android studio design preview, what should i do? How can I fix it?
BottomApp Bar is not showing in my phone while testing, but showing in android studio design preview, what should i do? How can I fix it?
I have something very strange:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<DrawerLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/frameLayoutRoot"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical"
android:visibility="invisible"
android:layout_margin="10dp">
<fragment
android:id="#+id/fooFragment"
android:name="net.mydomain.android.FooFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:fitsSystemWindows="false"
app:itemBackground="#drawable/layout_background"
app:menu="#menu/activity_single_view" />
</DrawerLayout>
</layout>
Please note android:visibility="invisible" of FrameLayout. The normal screen is exactly as expected - nothing shows:
However, picture-in-picture shows the following:
It shows the content (the fragment) outside of FrameLayout that is supposed to be invisible.
Could anyone shed some light on this?
The picture-in-picture is done by following the official guideline. Nothing special.
[Edit] 2019-08-26:
I added
android:layout_margin="10dp"
to the invisible FrameLayout. The result is exactly the same. This means the gray box is the root layout.
I have made a design for TabLayout, but I can't make the size fit with 2 different screens. I use two different screens like tablet and android phone.
How can I fix it?
This is my XML file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
tools:context="com.inducesmile.androidmusicplayer
.fragment.LibraryFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/colorMaroon">
<ImageView
android:layout_width="match_parent"
android:layout_height="102dp"
android:src="#drawable/logo1"/>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
app:tabTextColor="#color/colorWhite"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorMaroon"
app:tabMode="fixed"
app:tabIndicatorColor="#color/colorGold"
app:tabTextAppearance="#style/custTab"
app:tabSelectedTextColor="#color/colorGold"
android:layout_gravity="top"/>
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
I want to make 4 menu/fragments with TabLayout for the details, my XML was worked but the problem is the size not optimize if I run in tablet screen.
You need to make the layout responsive in order to view it in tablet, mobile or any other android based mobile. To make the layout responsive, we use Constraint Layout.
I'm trying to build a BottomSheet that contains a RecyclerView in it. I used a NestedScrollView and set its behavior as "bottom_sheet_behavior". The first time the app run, it's popping up normally, but when I collapse the BottomSheet and select an item from the spinner, it popping up with a space below it.
This is just happening on android 8, not the other versions.
On the other hand, when I remove RecyclerView, it works normally.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:background="#c9c5c5"
android:elevation="8dp"
android:entries="#array/seasons"
android:layoutDirection="rtl"
android:spinnerMode="dialog"
android:textAlignment="center"
android:textDirection="rtl" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="300dp"
android:fillViewport="true"
android:background="#color/colorPrimary"
android:elevation="6dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/activity_Recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
First run
After select an item from spinner
After a long effort finally found the problem. That was because of using this library ==> Searchable Spinner . I replaced it with simple spinner and it works fine!
Point:: Always use updated and supported libraries :|
I am creating an application for pre-L (exactly API 9+) devices using AppCompat support library.
The problem I have is related to AppCompat's Navigation drawer: if I have a drawer in my layout and I am initializing it, none of the EditText elemenets in my fragments cannot be focused (they are getting fosus for a split-second, and then they lose it; the soft-keyboard is not showing up).
I am using only an activity into which I load fragments:
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?android:windowContentOverlay">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="#drawable/toolbar_shadow"/>
<FrameLayout
android:id="#+id/app_fragment"
android:layout_below="#id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/scan_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_scan"
app:borderWidth="0dp"
app:elevation="4dp"/>
</RelativeLayout>
</LinearLayout>
<include layout="#layout/drawer_content"/>
I tested the code without initializing the drawer and everything is working fine. Any idea what could be causing this problem?
So I found what was the issue. I don't know why, probably because the touch event was going trough the drawer, I had in my code this line which was disabling any events on everything under DrawerLayout:
drawer.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);