Skip to content Skip to sidebar Skip to footer

Floatingactionbutton Onclicklistener Not Working On Api 17

my FAB onClick is not working on API 17, but on API 21 it's working fine. I'm using: compile 'com.android.support:design:23.+' FAB layout:

Solution 1:

SOLVED!

On my layout, the FloatingActionButton was bellow of a RecyclerView, and when I click on the Fab, I was clicking on the RecyclerView (that was empty)

Before:

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_awesome_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/primary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/myFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_gravity="bottom"
        android:layout_marginBottom="26dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        app:backgroundTint="#FFC107"
        android:clickable="true"
        android:elevation="@dimen/design_fab_elevation"
        android:src="@drawable/ic_add_24dp"
        app:borderWidth="0dp"
        android:layout_alignParentTop="false"
        android:layout_alignParentRight="false"
        android:layout_alignWithParentIfMissing="false"
        android:layout_alignParentLeft="false" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/my_awesome_toolbar">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/my_awesome_toolbar"
            android:layout_marginTop="?attr/actionBarSize" />
    </android.support.v4.widget.SwipeRefreshLayout>

After:

<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><android.support.v7.widget.Toolbarandroid:id="@+id/my_awesome_toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="@color/primary"android:elevation="4dp"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /><android.support.v4.widget.SwipeRefreshLayoutandroid:id="@+id/swipeRefreshLayout"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/my_awesome_toolbar"><android.support.v7.widget.RecyclerViewandroid:id="@+id/rv"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@id/my_awesome_toolbar"android:layout_marginTop="?attr/actionBarSize" /></android.support.v4.widget.SwipeRefreshLayout><android.support.design.widget.FloatingActionButtonandroid:id="@+id/myFAB"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentEnd="true"android:layout_gravity="bottom"android:layout_marginBottom="26dp"android:layout_marginLeft="16dp"android:layout_marginRight="16dp"app:backgroundTint="#FFC107"android:clickable="true"android:elevation="@dimen/design_fab_elevation"android:src="@drawable/ic_add_24dp"app:borderWidth="0dp"android:layout_alignParentTop="false"android:layout_alignParentRight="false"android:layout_alignWithParentIfMissing="false"android:layout_alignParentLeft="false" /></RelativeLayout>

Post a Comment for "Floatingactionbutton Onclicklistener Not Working On Api 17"