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);
Related
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 :|
Actually there is already similar question
BringToFront doesn't work inside a coordinator layout
However no of suggestions helped me to make bringToFront work within a coordinatorlayout.
Here is the layout-xml
<?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"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/main_content_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
android:id="#+id/navigation_drawer_container"
android:name="..."
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/..."
android:clickable="true"
android:layout_gravity="bottom|end"
android:layout_marginRight="20dp"
android:layout_marginBottom="60dp"
app:borderWidth="0dp"/>
<CustomView
android:id="#+id/customview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="gone"
app:layout_behavior="..."/>
</android.support.design.widget.CoordinatorLayout>
The custom view is inherited from FrameLayout. It can change its height.
To bring the custom view to the front first I tried to add:
mCustomView.bringToFront();
Then
mCustomView.requestLayout();
mCustomView.invalidate();
Finally also
((View)mCustomView.getParent()).requestLayout();
But without success. The button is still on the top.
Did I missed anything?
Maybe there other possibilities to bring the custom view to front or to put the button under custom view?
I also tried to add a behaviour to the button, but since it's visibility depends not only on the custom view I thrown this approach away.
Thank you for any help in advance.
I finally found a workaround - if I set setEnabled(false) on the AppBar, it goes to the background and I can draw other stuff over it regardless of API level.
I have a main activity with a appbar layout(also containing a navigation view) and a fragment with a tablayout . I want the user to be able to hide and show both of them while scrolling like Google Play Music app.But I just can't get the app bar to hide as it is not in the fragment although the tablayout is getting hidden fine.Also I can't move the appbar layout into the fragment as this will make my code for switching between fragments using navigation view very complicated.I am using coordinator layout for achieving this.How do I achieve this?.My code is as below-
WelcomeActivity
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/welcome_toolbar"
layout="#layout/default_toolbar_layout"
app:layout_scrollFlags="scroll|enterAlways"/>
<FrameLayout
android:id="#+id/welcome"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways">
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/welcome_nav"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/welcome_menu_drawer"/>
</android.support.v4.widget.DrawerLayout>
Myfragment.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/toolbar_gradient">
<android.support.design.widget.AppBarLayout
android:id="#+id/welcome_feeds_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="#+id/welcome_feeds_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/toolbar_gradient"
app:tabGravity="fill"
app:tabSelectedTextColor="#fff"
app:tabIndicatorColor="#color/accent"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/welcome_feeds_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.software.shell.fab.ActionButton
android:id="#+id/welcome_feeds_fab"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|right"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:button_color="#color/accent"
app:image="#mipmap/add"
app:image_size="24dp"
/>
</android.support.design.widget.CoordinatorLayout>
I haven't tried your code yet.....
Is your tabLayout correctly swipe out the screen on scrolling?
Have you tried to move inside CoordinatorLayout also the Toolbar?
To use the features by design Library all the elements have to be inside CoordinatorLayout and you have to set as your needs the correct property "app:layout_scrollFlags"
I have spent a lot of hours trying to find the problem with ActionBarDrawerToggle, but the problem is in my main layout.
Let me show what the problem is.
Here is example, how it looks like initally after application start.
As you can see hamburger is present but not shown right now.
Than if swipe drawer menu it appears.
It looks as it should look like, but it can disappear suddenly, when for example invalidateOptionsMenu() was called.
So I have tried to find the problem with toggle, but it is in my layout
Here is my layout xml file.
<?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/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear_layout_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:visibility="gone"
app:theme="#style/MainAppTheme.ToolbarMain"
app:titleTextAppearance="#style/MainAppTheme.Toolbar.Title" />
</LinearLayout>
<ViewStub
android:id="#+id/stub_progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="#+id/progress_bar_buttons"
android:layout="#layout/view_stub_progressbar_bg" />
</FrameLayout>
<ScrollView
android:id="#+id/frame_layout_drawer_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fillViewport="true">
</ScrollView>
<ScrollView
android:id="#+id/frame_layout_drawer_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fillViewport="true" />
</android.support.v4.widget.DrawerLayout>
The problem is in the last ScrollView, without last/right scroll view everything works fine. By the way this layout works fine with two drawers, but only hamburger is missed in this case.
I guess the problem is that navigation drawer toogle conflicts with two navgiation drawer view.
Because it doesn't matter what kind of view is with gravity end, it will not show hamburger in this case (if view with gravity end is present)
Please help to solve this problem, cause I have no idea how to deal with it, I need two drawers anyway.
Any help will be highly appreciated, thanks.
This is a pretty interesting issue but I think I have a solution. Well 2 solutions,
Have you creating a Frame Layout that houses two separate android.support.v4.widget.DrawerLayout layouts?
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--your content -->
<ScrollView
android:id="#+id/frame_layout_drawer_left"
android:layout_width="0dp"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/frame_layout_drawer_right"
android:layout_width="0dp"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>
the imbed the second drawer layout inside of the root
android.support.v4.widget.DrawerLayout.
sample xml
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--your content -->
<ScrollView
android:id="#+id/frame_layout_drawer_left"
android:layout_width="0dp"
android:layout_height="match_parent"/>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/frame_layout_drawer_right"
android:layout_width="0dp"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>
</android.support.v4.widget.DrawerLayout>
I have implemented material navigation drawer and toolbar in MainActivity. For implementing the navigation drawer and to ensure it shows up behind the status bar I have used following code for toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:fitsSystemWindows="true"
android:theme="#style/ToolbarTheme">
</android.support.v7.widget.Toolbar>
and included this in activity_main.xml as follows:
<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/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
........
in styles.xml I am using following attribute,
<item name="android:windowTranslucentStatus">true</item>
With this everything is working just fine and I get the following result,
The problem occurs when i click on the edit text view (00.00). The moment that edit text view or any edit text view in the page is clicked, the toolbar just expands. See image below:
Now, I was able to rectify the issue by placing android:fitsSystemWindows="true" in activity_main.xml as follows:
<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/navigation_drawer"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">
........
My question is, though this solution works but I am not sure as to why do I have to use the same attribute twice in layout file? And what made the toolbar expand? Also, is this the right approach to tackle this issue?
Edit - Removing android:fitsSystemWindows="true" from toolbar.xml and placing it in drawer layout results in the main activity yielding correct results but other activities have a white bar. See image below.
I had the same problem that you and I will tell you what I did for fix it
1) Defining the toolbar.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolBarDetalleContacto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:layout_collapseMode="pin"
app:theme="#style/Theme.GpsFriends.Material">
</android.support.v7.widget.Toolbar>
The trick is to use this attribute in your activity xml inside a <android.support.v4.widget.DrawerLayout> parent component and set here the property android:fitsSystemWindows="true" (also in your toolbar.xml). If you dont use DrawerLayout the permanent grey color in your colorPrimaryDark attribute wont be change, will be always grey and just grey.
2) Defining your activity xml:
<android.support.v4.widget.DrawerLayout 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:orientation="vertical"
android:fitsSystemWindows="true"
tools:context="com.wherefriend.activities.agregaramigos.AgregarAmigosActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/toolbar_main_gps_friends"
layout="#layout/toolbar_gps_friends"
></include>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bBuscar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:onClick="buscarAmigos"
android:text="Buscar" />
<EditText
android:id="#+id/etfragmentCorreo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/bBuscar"
android:ems="10"
android:inputType="textEmailAddress" />
</RelativeLayout>
<ListView
android:id="#+id/listaResultado"
android:divider="#drawable/horizontal_linear_layout_divider"
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
As you can see, I defined first child activity xml UI as DrawerLayout but just below I use <LinearLayout> to include my whole User interface View compontents. At first my Toolbar and then the rests of the components.
The result is like that, testing in a real Nexus 4 - LG API versiĆ³n 22: