Reputation: 155
I have an application with one main activity and some fragment, every fragment is a list fragment, but, in some of them, I need to add a FloatingActionButton with a custom action, and I would like preserve the auto generated adapter for that list. If I add the FloatingActionButton directly to the xml the list disapper, how can I add the button?
This is my fragment xml code
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
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/list"
android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context="it.ivannotarstefano.cojule.activity.PlayerFragment"
tools:listitem="@layout/fragment_player" >
</android.support.v7.widget.RecyclerView>
And I have tried to add the FloatingActionButton in this way
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
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/list"
android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context="it.ivannotarstefano.cojule.activity.PlayerFragment"
tools:listitem="@layout/fragment_player" >
<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="10dp"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_add_black_24dp"
app:backgroundTint="#fff700" />
</android.support.v7.widget.RecyclerView>
Upvotes: 0
Views: 552
Reputation: 122
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.v7.widget.RecyclerView 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/list"
android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="10dp"
android:baselineAlignBottom="true"
android:clickable="true"
android:focusable="true"
android:src="@drawable/side_nav_bar"
app:backgroundTint="#fff700" />
</FrameLayout>
Upvotes: 1