juotua
Last Updated: February 25, 2016
·
7.527K
· bighands
Profile

Facebook Login Button & Android

OK for all those following the Facebook Developers guide (I think the latest is 3.0) you will eventually hit a brick wall when asked to implement :

<com.facebook.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" />

So, instead of trying to add the tag into you xml activity (such as activitymain.xml) you will have to first add the property android:id to the LinearLayout tag in the activitymain.xml file (or whatever is your main activity file) :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutloginbtn"   
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:orientation="vertical">

Open your main activity java file and implement the your login button :

public void onCreate(Bundle savedInstanceState) {

LinearLayout mLayout = (LinearLayout) findViewById(R.id.layoutloginbtn);

LoginButton mLoginButton = new LoginButton(this);

mLoginButton.setLayoutParams(new LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT));

 mLoginButton.setBackgroundResource(
        R.drawable.com_facebook_login);

mLayout.addview(mLoginButton);

This should have the same effect as trying to add the LoginButton through the xml file.

Say Thanks
Respond