[英]facebook sdk v4.2 shows Error inflating class com.facebook.login.widget.LoginButton
I know this is common question, but I have read through all the stack overflow questions without finding an answer.It shows Error inflating class com.facebook.login.widget.LoginButton. 我知道这是一个常见问题,但是我已经通读了所有堆栈溢出问题,但没有找到答案,它显示了使类com.facebook.login.widget.LoginButton膨胀的错误。 Here my code
这是我的代码
<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_marginBottom="30dp"
android:layout_below="@+id/or"
android:layout_alignLeft="@+id/login_email_tv"
android:layout_alignRight="@+id/login_email"
android:layout_marginTop="10dp"
/>
and this is my basic code 这是我的基本代码
public class Login_Activity extends Activity { 公共类Login_Activity扩展了活动{
// Your Facebook APP ID
private static String APP_ID = "xxxxxxxxxxxxxxxxxxx";
CallbackManager callbackManager;
//ImageButton fb_login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity);
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
} }
Any one please give me suggestions for this.Am new to android 任何人都可以给我这个建议。是Android新手
Have you integrated the Facebook SDK into your project? 您是否已将Facebook SDK集成到您的项目中? Check your
build.gradle
检查您的
build.gradle
You need to add the facebook module to the dependencies in build.gradle
您需要将facebook模块添加到
build.gradle
的依赖build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':facebook')
}
As well, the Facebook module should be imported in settings.gradle
: 同样,Facebook模块也应导入
settings.gradle
:
include ':app', ':facebook'
Initialize Facebook SDK before SetContentView
: 在
SetContentView
之前初始化Facebook SDK:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.login_activity);
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.