Android SearchView not positioning correctly - android

I downloaded some sample code here https://trinitytuts.com/get-contact-list-and-show-in-custom-listview-android/ which searches and lists contacts in my phone. The resulting app builds and loads well. I believe it uses the Android search widget as at the top of my mainactivity I have :
import android.widget.SearchView
(However I do not have a searachable.xml file which I have seen in some sources
is a feature of this Search Widget)
According to Google, I believe the searchview widget can be
positioned anywhere in the activity (I don't want it at the top
of the activity, I want it at the bottom):
http://developer.android.com/guide/topics/search/search-dialog.html#TheBasics
According to Google in the link above the the search dialogue always appears at the top of an activity, however I am lead to believe the widget can be positioned in different places.
But when I try to change the position of the Searchview in my activity, it doesn't display.
For example, this works fine in my activity_main xml, the searchview is at the top of the page:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<SearchView
android:background="#5b74a8"
android:queryHint="howdy"
android:padding="8dp"
android:id="#+id/searchView"
android:drawableLeft="#android:drawable/ic_menu_search"
android:layout_width="match_parent"
android:singleLine="true"
android:layout_gravity="right"
android:layout_height="wrap_content"></SearchView>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contacts_list"></ListView>
</LinearLayout>
But in this case the SearchView isn't visible at all. Any ideas how I can place my search widget at the bottom?
<LinearLayout 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"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/contacts_list"></ListView>
<SearchView
android:background="#5b74a8"
android:queryHint="howdy"
android:padding="8dp"
android:id="#+id/searchView"
android:drawableLeft="#android:drawable/ic_menu_search"
android:layout_width="match_parent"
android:singleLine="true"
android:layout_gravity="right"
android:layout_height="wrap_content"></SearchView>
</LinearLayout>

Your list view is hiding SearchView..
You can do following to see its going at the end
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.codepath.mytestapp.MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:id="#+id/contacts_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="right"
android:background="#5b74a8"
android:drawableLeft="#android:drawable/ic_menu_search"
android:padding="8dp"
android:queryHint="howdy"
android:singleLine="true"
/>
</RelativeLayout>

Related

Floating Action Button in android webview

I've created a simple android app with webview to showcase my website, so now am trying to add FAB so users can share articles with that button. Wherever I place the code, either it crashes or just not being useful when I place inside webview because it gets scrolls, am sharing my code below, can you please help with the alignment, I want FAB to be a sticky button at the right bottom of the app.
<?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">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_behavior="#string/appbar_scrolling_view_behavior">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<ProgressBar
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
style="?android:attr/progressBarStyle"
/>
</RelativeLayout>
Can you please guide me with the correct way of doing it, after this I've to change JAVA file.
Try this,
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal"
android:elevation="6dp"
android:layout_alignParentBottom="true">
<YOUR_FAB_HERE
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="25dp"
android:visibility="visible"
app:srcCompat="#drawable/ic_file_upload_white_24dp"
tools:ignore="VectorDrawableCompat" />
</RelativeLayout>
<--- your additional layout here ----->
</RelativeLayout>

Android cardview first item and last item not showing correctly

So I follow an Android tutorial from ude*y, everything works perfectly, the only problem is the first and last item of cardview not showing correctly.
I think you have to margin or padding as your requirement.
<LinearLayout 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/tryagain"
android:gravity="center"
android:visibility="gone"
android:text="#string/no_data_available" />
</RelativeLayout>
</LinearLayout>
You want see more full card view example, please following this github:
https://github.com/dharmakshetri/CardViewExample/blob/master/app/src/main/res/layout/main.xml
and full source code:
CardViewExample

Android Webview selection handles and menu seen through view on top - how to hide it?

I have a main Webview and a bottom sheet that shows up occasionally, overlaying it. The bottom one is also a Webview, shown green.
The problem is that if there is any selection in the main view, the selection handles and menu show through the bottom one and I want them to hide behind.
Here is the layout:
<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/my_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.gary.testandroid.TestActivity"
tools:showIn="#layout/activity_test">
<com.example.gary.testandroid.BrowseView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:clipToPadding="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lview1"
android:elevation="0dp"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight=".62"/>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottom_view"
android:layout_alignParentBottom="true"
android:elevation="24dp"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight=".38"/>
</LinearLayout>
</RelativeLayout>

Remove space between app border and a List view

I'm developing an android app which uses a list view using android studio.But when i use it a space is being displayed between list view and app borders.how can i remove that space?? Like in this pic I need my app to be designed .The following code is XML code for listview i got in my editor.Suggest the changes for space removal.
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
The padding is due to the padding provided to RelativeLayout
From your XML code remove padding by making you code look like
<RelativeLayout
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"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

Material Design Floating Button (FAB) Blocking RecyclerView

I'm facing a strange issue while trying to use a material design FAB button in my app. I'm using this library (https://github.com/makovkastar/FloatingActionButton).
My activity xml has a RecyclerView and the FAB. But the FAB is actually blocking the lower portion of the entire screen. Something like this :
http://i.stack.imgur.com/FtEcb.png
It can be seen in the picture that the RecyclerView containing the cards is being blocked by the Floating Button. Here's the code I'm using:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity">
<fragment
class="com.rubberduck.zoop.fragments.OffersFragment"
android:id="#+id/fragment_enter_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:layout="#layout/fragment_offer" />
<com.melnykov.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="8dp"
android:elevation="6dp"
android:src="#drawable/ic_place_white_24dp"
fab:fab_colorNormal="#color/color_accent"
fab:fab_colorPressed="#color/color_accent_pressed"
fab:fab_colorRipple="#color/ripple" />
</LinearLayout>
fragment_offer.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="com.rubberduck.zoop.fragments.OffersFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_offers"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="#+id/card_offer"
layout="#layout/offer_card" />
</LinearLayout>
When you use a LinearLayout as the container for your fragment and FloatingActionButton, items do not overlap: The LinearLayout gives the full width to each component when you use orientation="vertical". Instead, as per the FloatingActionButton readme, you should use a FrameLayout (which allows items to overlap - ensuring the FloatingActionButton appears above the RecyclerView):
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity">
<fragment
class="com.rubberduck.zoop.fragments.OffersFragment"
android:id="#+id/fragment_enter_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragment_offer" />
<com.melnykov.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="8dp"
android:elevation="6dp"
android:src="#drawable/ic_place_white_24dp"
fab:fab_colorNormal="#color/color_accent"
fab:fab_colorPressed="#color/color_accent_pressed"
fab:fab_colorRipple="#color/ripple" />
</FrameLayout>

Categories

Resources