Home > Software engineering >  Floating Action Button in android webview
Floating Action Button in android webview

Time:10-13

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.

CodePudding user response:

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>
  • Related