当前位置: 首页 > 知识库问答 >
问题:

我正在使用GOWONG/Material-Sheet-Fab,但它显示了我的错误。有人能帮我吗?

黄沈浪
2023-03-14

这是我的Fab活动

public class Fab extends FloatingActionButton implements AnimatedFab {

public Fab(Context context) {
    super(context);
}


@Override
public void show() {
    show(0, 0);
}
@SuppressLint("RestrictedApi")
@Override
public void show(float translationX, float translationY) {

    setVisibility(View.VISIBLE);
}

/**
 * Hides the FAB.
 */
@SuppressLint("RestrictedApi")
@Override
public void hide() {

    setVisibility(View.INVISIBLE);
}

}

 // MATERIAL ANIMATED FAB
    Fab fab = findViewById(R.id.fab);
    View sheetView = findViewById(R.id.fab_sheet);
    View overlay = findViewById(R.id.overlay);
    int sheetColor = getResources().getColor(R.color.fab_sheet_color);
    int fabColor = getResources().getColor(R.color.fab_color);

    // Initialize material sheet FAB
    materialSheetFab = new MaterialSheetFab<>(fab, sheetView, overlay,
            sheetColor, fabColor);
    materialSheetFab.setEventListener(new MaterialSheetFabEventListener() {
        @Override
        public void onShowSheet() {
            // Called when the material sheet's "show" animation starts.

        }

        @Override
        public void onSheetShown() {
            // Called when the material sheet's "show" animation ends.

        }

        @Override
        public void onHideSheet() {
            // Called when the material sheet's "hide" animation starts.
        }

        public void onSheetHidden() {
            // Called when the material sheet's "hide" animation ends.
        }
    });

这是我的logcat

进程:com.teepe.teepe,PID:29259 java.lang.RuntimeException:无法启动活动组件Info{com.teepe.teepe/com.teepe.teepe.MainActivity}:java.lang.ClassCastException:Android.Support.Design.Widget.FloatingActionButton无法强制转换为com.teepe.teepe.Fab(位于Android.app.ActivityThread.PerformLaunchActivity(ActivityThread.java:2646)(位于Android.app.ActivityThread.HandleLaunchActivity(tton不能转换为com.teepe.teepe.mainactivity.onCreate(mainactivity.java:95)在Android.app.activity.performCreate(activity.java:6662)在Android.app.instrumentation.callactivityonCreate(instrumentation.java:1118)在Android.app.activitythread.performLaunchActivity(activitythread.java:2599)在Android.app.activitythread.handleLaunchActivity(activitythread.java:2707) 在android.app.activitythread.-wrap12(activitythread.java) 在Android.app.ActivityThread$H.HandleMessage(ActivityThread.java:1460) 在android.os.handler.dispatchmessage(handler.java:102) 在android.os.looper.loop(looper.java:154) 在android.app.activityThread.main(activityThread.java:6077) 在java.lang.Reflect.Method.Invoke(原生方法) 在com.android.internal.os.zygoteInit$methodandargscaller.run(zygoteInit.java:866) 在com.android.internal.os.zygoteinit.main(zygoteinit.java:756) 

共有1个答案

齐锐进
2023-03-14

如错误所述,由:java.lang.ClassCastException:Android.Support.Design.Widget.FloatingActionButton引起的不能在com.teepe.teepe.MainActivity.onCreate(MainActivity.java:95)强制转换为com.teepe.teepe.fab,请在MainActivity中检查您使用的库中的这一行代码:

<com.gordonwong.materialsheetfab.sample.Fab
       android:id="@+id/fab"
       style="@style/Widget.MaterialSheetFab.Fab"
       android:layout_alignParentBottom="true"
       android:layout_alignParentEnd="true"
       android:layout_alignParentRight="true" />

将您的 更改为 布局中的 mainactivity(最好是 activity_main.xml,您的 r.id.fab声明在其中。

希望这能修复你的错误。点击答案旁边的复选标记,将其从灰色切换到填充。

 类似资料: