我在使用子FloatingActionButton
处理menu
时遇到问题。我需要在单击子菜单时添加操作。我刚刚从网上获得了这个FloatingActionButton
代码,我想在其中加入操作,感谢您的帮助。
这是我的FloatingActionButton
:
即时使用com.github.clans:fab:1.6.2
库
这是我的onCreateView代码:
FloatingActionButton fabsnail = v.findViewById(R.id.fabsnailtrail);
FloatingActionButton fabprox = v.findViewById(R.id.fabproximity);
FloatingActionButton fabnav = v.findViewById(R.id.fabnavigations);
fabsnail.setOnClickListener(this);
fabprox.setOnClickListener(this);
fabnav.setOnClickListener(this);
fabsnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(),"Snail Trail!" , Toast.LENGTH_SHORT);
}
});
fabprox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(),"Proximity!" , Toast.LENGTH_SHORT);
}
});
fabnav.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(),"Navigations!" , Toast.LENGTH_SHORT);
}
});
这是XML文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<com.github.clans.fab.FloatingActionMenu
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false"
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="#a21e23"
fab:menu_colorPressed="#a21e23"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_labels_style="@style/MenuLabelsStyle"
fab:menu_fab_size="normal"
fab:menu_icon="@mipmap/negative"
fab:menu_labels_colorNormal="#333"
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="right"
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/fabsnailtrail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/snailtrail"
fab:fab_label=" Snail Trail "
fab:fab_colorNormal="#a21e23"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fabproximity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/proximity"
fab:fab_label=" Proximity "
fab:fab_colorNormal="#a21e23"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fabnavigations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/navigations"
fab:fab_label=" Navigations "
fab:fab_colorNormal="#a21e23"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
答案 0 :(得分:2)
您应该在Toast
中添加 show 方法。
尝试使用它。
Toast.makeText(getContext(),"Navigations!" , Toast.LENGTH_SHORT).show();