Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

customize Android Facebook Login button

I want to customize the look of the Facebook login button which we get along with the Facebook sdk for android (facebook-android-sdk-3.0.1). I want a simple android button which has title "Login via Facebook". I could not find any documentation regarding that.

So if any one knows on how to do it in a simple way, please tell me or direct me on how to do it.

like image 882
dora Avatar asked May 01 '13 07:05

dora


People also ask

How do I add a login button to Facebook?

You can find the app review requests on the left-hand side of your home screen. From there, scroll through the list of options and click Request for any permissions you'd like to add. You'll need to fill out a form that confirms your Facebook Login button is live and can be tested.

What is the log back in button on Facebook?

The Login button is a simple way to trigger the Facebook Login process on your website or web app. If someone hasn't logged into your app yet, they'll see this button, and clicking it will open a Login dialog, starting the login flow.

What is Facebook SDK Android?

The Facebook SDK for Android gives you access to the following features: Facebook Login — A secure and convenient way for people to log into your app or website by using their Facebook credentials. Sharing — Enable people to post to Facebook from your app. People can share, send a message, and share to stories.


Video Answer


2 Answers

In order to have completely custom facebook login button without using com.facebook.widget.LoginButton.

According to facebook sdk 4.x,

There new concept of login as from facebook

LoginManager and AccessToken - These new classes perform Facebook Login

So, Now you can access Facebook authentication without Facebook login button as

layout.xml

    <Button             android:id="@+id/btn_fb_login"             .../> 

MainActivity.java

    @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);          FacebookSdk.sdkInitialize(this.getApplicationContext());          callbackManager = CallbackManager.Factory.create();          LoginManager.getInstance().registerCallback(callbackManager,                 new FacebookCallback<LoginResult>() {                     @Override                     public void onSuccess(LoginResult loginResult) {                         Log.d("Success", "Login");                      }                      @Override                     public void onCancel() {                         Toast.makeText(MainActivity.this, "Login Cancel", Toast.LENGTH_LONG).show();                     }                      @Override                     public void onError(FacebookException exception) {                         Toast.makeText(MainActivity.this, exception.getMessage(), Toast.LENGTH_LONG).show();                     }                 });          setContentView(R.layout.activity_main);          Button btn_fb_login = (Button)findViewById(R.id.btn_fb_login);          btn_fb_login.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View view) {                   LoginManager.getInstance().logInWithReadPermissions(MainActivity.this, Arrays.asList("public_profile", "user_friends"));             }         });      }  @Override  protected void onActivityResult(int requestCode, int resultCode, Intent data) {     super.onActivityResult(requestCode, resultCode, data);      callbackManager.onActivityResult(requestCode, resultCode, data);  } 
like image 61
TejaDroid Avatar answered Sep 28 '22 12:09

TejaDroid


You can use styles for modifiy the login button like this

<style name="FacebookLoginButton">     <item name="android:textSize">@dimen/smallTxtSize</item>     <item name="android:background">@drawable/facebook_signin_btn</item>     <item name="android:layout_marginTop">10dp</item>     <item name="android:layout_marginBottom">10dp</item>     <item name="android:layout_gravity">center_horizontal</item> </style> 

and in layout

<com.facebook.widget.LoginButton         xmlns:fb="http://schemas.android.com/apk/res-auto"         android:id="@+id/loginFacebookButton"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         fb:login_text="@string/loginFacebookButton"         fb:logout_text=""         style="@style/FacebookLoginButton"/> 
like image 24
Filsh Avatar answered Sep 28 '22 11:09

Filsh