gpt4 book ai didi

android - float 操作按钮转换问题

转载 作者:行者123 更新时间:2023-11-29 14:26:29 25 4
gpt4 key购买 nike

我收到这个错误:

Caused by: java.lang.ClassCastException: com.github.clans.fab.FloatingActionButton cannot be cast to 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>

汽车.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);
}
});

}
}

最佳答案

当您在 xml com.github.clans 中使用外部库元素时,您的 Activity 正在从支持库导入并且导入是 android.support.design.widget.FloatingActionButton .fab.FloatingActionButton。使用正确的导入,您将不会遇到 ClassCastException

确保你的 Activity 有

导入 com.github.clans.fab.FloatingActionButton

不是

导入 android.support.design.widget.FloatingActionButton

FloatingActionMenu 类似。确保您的导入以您正在使用的库的包名称开头。通常人们会遇到这种错误,因为 Android Studio 会自动导入

关于android - float 操作按钮转换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44506821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com