floatingsearchview RTL Layout - java

I'm trying to use floatingsearchview in my app. My app has RTL layout and when I use floatingsearchview it doesn't match with RTL layout. How can I fix it?
Here is my xml code:
<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:id="#+id/parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.arlib.floatingsearchview.FloatingSearchView
android:id="#+id/floating_search_view"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layoutDirection="rtl"
app:floatingSearch_close_search_on_keyboard_dismiss="false"
app:floatingSearch_dimBackground="false"
app:floatingSearch_dismissOnOutsideTouch="true"
app:floatingSearch_leftActionMode="showHamburger"
app:floatingSearch_menu="#menu/menu_search_view"
app:floatingSearch_searchBarMarginLeft="#dimen/search_view_inset"
app:floatingSearch_searchBarMarginRight="#dimen/search_view_inset"
app:floatingSearch_searchBarMarginTop="#dimen/search_view_inset"
app:floatingSearch_searchHint="#string/search_hint"
app:floatingSearch_showSearchKey="true"
app:floatingSearch_suggestionsListAnimDuration="250" />
</android.support.design.widget.AppBarLayout>

Related

How do I make the background of my navigation drawerlayout for it to be the activity_main.xml in xml in android studio?

I am trying to create a separate page for my drawerlayout and add the background as the activity_main.xml so that the two pages are separate but I can't manage to do this. How do I do this in xml in android studio? This is my code for my drawerlayout page in xml in android studio. What changes do I have to make for this to work?
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:elevation="4dp"
android:background="#6666ff"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
</androidx.appcompat.widget.Toolbar>
<FrameLayout
android:background="#+id/main_background"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/navig_menu"
android:layout_width="wrap_content"
android:layout_height="match_parent">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>

Part of Linear Layout hide under Action bar

I know this may be a stupid question, however as a newbie i cant get to work around it.
So i want to add actionBar with Back Navigation Button and part of LinearLayout is hidden. How could i solve the problem ??
Code
MainActivity.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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:elevation="4dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:navigationIcon="#drawable/ic_arrow_back_black_24dp"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Content Layout
<?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"
android:padding="16dp"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main"
>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_productname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="15"
app:errorEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Name"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Price"
android:inputType="numberDecimal|numberSigned"/>
</android.support.design.widget.TextInputLayout>
<!--Add Product-->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Product"
android:onClick="addProduct"/>
</LinearLayout>
Expectation
I manually set margin-top to lower Linearlayout and show the expected result.
You need to add the layout behaviour to your content
<include layout="#layout/content_main"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
You can try this. Since you are using CoordinatorLayout you need to use layout_behaviour, layout_anchor and layout_anchorGravity to properly align the layout. Just add the following line in your include:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
So it will be like this:
<include layout="#layout/content_main"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>

Collapsing Toolbar is not scrollable

I‘m trying to create an app containing a collapsing toolbar. Below is the layout of my XML file. The intention was to make it collapsing but with my code everything is just fixed to its current position and not scrollable at all. Hope anyone has any suggestions.
As information: I’m using android studio and the system runs at API 26
<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"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.te.e5.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_height="300dp"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/coltoolbar"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
app:contentScrim="?attr/colorPrimary"
app:title="App Title"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:background="#drawable/materialbackground">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarid"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Change the flags sequence in CollapsingToolbarLayout like this
app:layout_scrollFlags="scroll|exitUntilCollapsed"
if you want the collapsing toolbar to scroll when user scrolls content then the first flag should be "scroll" always then "exitUntilCollapsed".
Solution:
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="com.birjuvachhani.myapplication.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
<!-- Main content goes here. -->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

My background is under navbar.How to set the background just below the navbar?

My background hides under the navbar.
How can I put the background start showing just below the navbar?
code:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/backgroundnew"
android:scaleType="centerCrop" />
In your activity_main.xml, Have you closed the toolbar correctly?
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="#layout/app_bar_main">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</LinearLayout>
If you didn't close your toolbar, the view is overlapped.

Recycler View is not scrolling in Navigation drawer

I have created a navigation drawer and in the main content of navigation drawer I have a RecyclerView but it's not scrolling. Initially I have put RecyclerView without NestedScrollView but that didn't work, so I tried putting it inside NestedScrollView but the latter didn't work also.
My navigation drawer XML is :
<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="com.roushan.assignment1.NavDrawerActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/nav_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/nav_toolbar_color"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<!-- MAIN CONTENT OF NAVIGATION DRAWER ACTIVITY -->
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp"
tools:openDrawer="start">
<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"
app:headerLayout="#layout/nav_drawer_header"
app:menu="#menu/activity_nav_drawer_drawer" >
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
As Mike pointed out , the way you have structured the layout is wrong. Please modify the layout as below:
<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="com.roushan.assignment1.NavDrawerActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/nav_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/nav_toolbar_color"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp"
tools:openDrawer="start">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
<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"
app:headerLayout="#layout/nav_drawer_header"
app:menu="#menu/activity_nav_drawer_drawer" >
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>

Categories