0

In my activity i had to create a custom web view so, i put it and i want to get a FAB in the same activity but i having no success on that. Here is my class code:

package com.mydomain.app;

import android.app.Activity;
import android.content.Context;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebView;

public class CustomWebView extends WebView {
    FloatingActionButton fab;

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        Activity activity = (Activity) context;
        fab = (FloatingActionButton) activity.findViewById(R.id.fab);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if(t >= oldt)
            fab.hide();
        if(t < oldt)
            fab.show();
    }
}

When the onScrollChanged is fired the app breaks. How can i get this FAB to show or hide it?

Edit 1:

Here is the log: enter image description here

Edit 2:

Here is the activity that i'm using this class:

<?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" >

    <RelativeLayout
        android:id="@+id/loading_panel"
        android:layout_centerInParent="true"
        android:elevation="4dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible"
        android:clickable="true">

        <ProgressBar
            style="@android:style/Widget.Material.ProgressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/corners"
            android:id="@+id/progressBar2"
            android:indeterminate="true"
            android:layout_centerInParent="true"
            android:indeterminateTintMode="src_atop"
            android:indeterminateTint="@color/colorAccent" />

    </RelativeLayout>

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/webViewContainer"
        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.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            app:backgroundTint="@color/colorAccent"
            app:fabSize="normal"
            android:src="@drawable/ic_apps"
            app:layout_anchor="@+id/webView"
            android:layout_margin="16dp"
            app:layout_anchorGravity="bottom|right|end"
            android:minHeight="179dp" />

        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swipeContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.usefashion.useapp.CustomWebView
                android:id="@+id/webView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:elevation="0dp"
                android:clickable="true">
            </com.usefashion.useapp.CustomWebView>

        </android.support.v4.widget.SwipeRefreshLayout>

    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>
Lucas Müller
  • 382
  • 1
  • 4
  • 21
  • Please edit your question and explain **in detail** what "the app breaks" means. If your app is crashing, use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Dec 15 '16 at 18:44
  • @CommonsWare Please, see Edit 1. – Lucas Müller Dec 15 '16 at 18:50
  • Presumably, you do not have a widget named `R.id.fab`, so `findViewById()` is returning `null`. Also, in the future, please post text of stack traces, not screenshots. – CommonsWare Dec 15 '16 at 18:53
  • @CommonsWare Please, see Edit 2. – Lucas Müller Dec 15 '16 at 18:55

0 Answers0