我收到此错误:
原因:java.lang.ClassCastException:com.github.clans.fab.FloatingActionButton 无法转换为 android.support.design.widget.FloatingActionButton。
这是我的代码:
车辆.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/tools">
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/material_design_android_floating_action_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="64dp"
android:layout_marginRight="16dp"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="@android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#3F51B5"
fab:menu_colorPressed="#3F51B5"
fab:menu_colorRipple="#3F51B5"
fab:menu_fab_size="normal"
fab:menu_icon="@drawable/ic_add"
fab:menu_labels_colorNormal="#3F51B5"
fab:menu_labels_colorPressed="#3F51B5"
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/material_design_floating_action_menu_item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/car"
fab:fab_label="Add Car"
fab:fab_size="mini"
fab:menu_colorNormal="#3F51B5"/>
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
Vechile.java
FloatingActionMenu materialDesignFAM;
FloatingActionButton floatingActionButton1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vehicle);
materialDesignFAM = (FloatingActionMenu)
findViewById(R.id.material_design_android_floating_action_menu);
floatingActionButton1 = (FloatingActionButton)
findViewById(R.id.material_design_floating_action_menu_item1);
floatingActionButton1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(VehicleActivity.this, Brand
Activity.class);
startActivity(intent);
}
});
}
}