The problem is that when I click on the floating button it does the action, but when I return to the main Activity, the floating menu is still open, why doesn't it close? I leave a GIF so you can see the problem better:
Code:
MainActivity.java
import com.github.clans.fab.FloatingActionButton;
import com.github.clans.fab.FloatingActionMenu;
public class MainActivity extends Activity {
FloatingActionMenu btn_flo_menu;
FloatingActionButton btn_flo_1, btn_flo_2, btn_flo_3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_flo_menu = (FloatingActionMenu) findViewById(R.id.icon_btn_flo_menu);
btn_flo_1 = (FloatingActionButton) findViewById(R.id.icon_btn_flo_1);
btn_flo_2 = (FloatingActionButton) findViewById(R.id.icon_btn_flo_2);
btn_flo_3 = (FloatingActionButton) findViewById(R.id.icon_btn_flo_3);
btn_flo_1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
editarPersona(0);
}
});
btn_flo_2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
btn_flo_3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
}
}
Activity_main.xml
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/base_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/icon_btn_flo_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="11dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="@android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#3F51B5"
fab:menu_colorPressed="#dc4b3f"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_size="normal"
fab:menu_icon="@drawable/fab_add"
fab:menu_labels_colorNormal="#3F51B5"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="3dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="8dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#f2f1f1"
fab:menu_labels_textSize="15sp"
fab:menu_openDirection="up"
fab:menu_shadowColor="#66aff198"
fab:menu_shadowRadius="4dp"
fab:menu_shadowXOffset="1dp"
fab:menu_shadowYOffset="4dp"
fab:menu_showShadow="true">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/icon_btn_flo_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_btn_flo_1"
fab:fab_label="@string/btn_flo_1"
fab:fab_size="mini"
android:clickable="false" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/icon_btn_flo_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon2"
fab:fab_label="Vacío"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/icon_btn_flo_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon3"
fab:fab_label="Vacío"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
Add this line in the class and you're done.
Actually it is not the button that should be closed, it is the
FloatingActionMenu
, I think it is better to validate if it is open to close it using the methodclose()
The code would be: