Fernando Payares Fernando Payares - 1 month ago 13
Android Question

How to set image from Uri to an Floating Action Button

I am using this https://github.com/Clans/FloatingActionButton for my menu.

i am getting some issues because whenever i try to set OnclickListener method it doesn't work.

final FloatingActionMenu menu = (FloatingActionMenu)findViewById(R.id.fam);
menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"hola",Toast.LENGTH_LONG).show();
}});


I am getting a NullPointerException.

the real problem is that i have two Floating Action buttons,i need to set an image from an uri on one of the fabs, i dont know if the library have its own onclick method, any sugesstion?

<com.github.clans.fab.FloatingActionMenu
android:id="@+id/fam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|right"
app:fab_colorNormal="#DA4336"
app:fab_colorPressed="#E75043"
app:fab_colorRipple="#99FFFFFF"
app:menu_shadowColor="#66000000"
app:menu_showShadow="true">

<com.github.clans.fab.FloatingActionButton
android:id="@+id/menu_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_slideshow"
fab:fab_label="Dashboard"
fab:fab_size="mini" />

<com.github.clans.fab.FloatingActionButton
android:id="@+id/menu_item2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_facejam"
fab:fab_label="Salir"
fab:fab_size="mini" />

</com.github.clans.fab.FloatingActionMenu>

Answer

You might want to take a look at this page from the samples.

Try using setOnMenuButtonClickListener instead of setOnClickListener , but before that I guess you need to add your fabs with this function addMenuButton and set all the listeners.

Cheers.

Comments