Android,Facebook登录按钮导致崩溃(SDK 4.0.0)



在我的活动.xml文件中,我包含了Facebook登录按钮(来自本文档)

    <com.facebook.login.widget.LoginButton
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp" />

我立刻收到警告说

The following classes could not be found:
    - com.facebook.login.widget.LoginButton

文件对说

将按钮添加到具有完整类名的布局XML文件中,com.facebook.widget.登录按钮

但改变这条底线毫无作用。应用程序立即崩溃,没有打开,日志猫中没有任何记录(在外部设备上测试)。

删除按钮,或将其更改为

    <Button
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp" />

停止了崩溃,但这是我第一次使用Facebook SDK,不知道常规按钮是否有效。

提前谢谢。

在膨胀视图之前添加FacebookSdk.sdkInitialize(getActivity().getApplicationContext());。。
-如果在活动中使用了此xml,请在setContentView()之前写上上面的行
-如果这个xml在片段中使用,请在inflater.inflate... 之前写下这一行

并且,只需忽略布局预览窗口中显示的警告

最新更新