我试图使用谷歌的新材料设计为我的新应用程序,首先可以在我的Android工作室找到它。所以我添加了一个第三方库。
此解决方案仅在我尝试将其发送到我的下一个屏幕时才会显示一个屏幕(使用Facebook登录按钮崩溃)。
我正在使用的库是这样的: https://github.com/navasmdc/MaterialDesignLibrary/
我使用普通的Facebook SDK
这是我的堆栈跟踪:
02-04 12:33:22.924 3726-3726/com.geniusgentlemen.gp_android_app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.geniusgentlemen.gp_android_app, PID: 3726
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.geniusgentlemen.gp_android_app/com.example.bart.gp_android_app.login_activity}: java.lang.ClassCastException: com.gc.materialdesign.views.
无法将ButtonRectangle强制转换为com.facebook.widget.LoginButton 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 在
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassCastException: com.gc.materialdesign.views.ButtonRectangle cannot be cast to com.facebook.widget.LoginButton
at com.example.bart.gp_android_app.login_activity.onCreate(login_activity.java:130)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
这里发生了什么?我试图更改Facebook登录按钮,这没有工作
login.xml文件
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".InitActivit">
<!-- The primary full-screen view. This can be replaced with whatever view
is needed to present your content, e.g. VideoView, SurfaceView,
TextureView, etc. -->
<!-- This FrameLayout insets its children based on system windows using
android:fitsSystemWindows. -->
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@drawable/background_test"
android:backgroundTintMode="src_over">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.facebook.widget.ProfilePictureView
android:id="@+id/profilePicture"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
facebook:preset_size="normal"
android:layout_gravity="center_horizontal|bottom"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="86dp" />
<com.facebook.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
facebook:confirm_logout="false"
facebook:fetch_user_info="true"
android:layout_gravity="center|top"
android:layout_below="@+id/speebee"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="SpeeBee"
android:id="@+id/speebee"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:textColor="#ff350012"
android:textSize="40dp"
android:focusableInTouchMode="false" />
</RelativeLayout>
</FrameLayout>
登录按钮var
的代码private LoginButton loginButton;
初始化的代码:
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
@Override
public void onUserInfoFetched(GraphUser user) {
login_activity.this.user = user;
updateUI();
handlePendingAction();
}
});
这些是规则124至132
这是handlePendingAction():
private void handlePendingAction() {
PendingAction previouslyPendingAction = pendingAction;
// These actions may re-set pendingAction if they are still pending, but we assume they
// will succeed.
pendingAction = PendingAction.NONE;
}
如要求进口:
import com.example.bart.gp_android_app.util.SystemUiHider;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.AppEventsLogger;
import com.facebook.FacebookAuthorizationException;
import com.facebook.FacebookOperationCanceledException;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.model.GraphPlace;
import com.facebook.model.GraphUser;
import com.facebook.widget.FacebookDialog;
import com.facebook.widget.LoginButton;
import com.facebook.widget.ProfilePictureView;
import com.geniusgentlemen.support_classes.Api;
import com.geniusgentlemen.support_classes.ApiFunctions;
import com.loopj.android.http.RequestParams;
import org.json.JSONException;
import java.util.List;