• 15
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Facebook Android sdk has a com.facebook.widget.LoginButton

I want to put my own image for the Login button. Is it possible ?

So far i've tried adding android:src="@drawable/facebook" to the layout file as an attribute to the button element with no luck

I ended up overriding the text to be empty string and then defining the setBackgroundResource of the button to my image (didn't need the dynamic login/logout text functionality)

<com.facebook.widget.LoginButton
        xmlns:fb="http://schemas.android.com/apk/res-auto"
        android:id="@+id/login_button"
        android:layout_width="249dp"
        android:layout_height="45dp"
        android:layout_above="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="30dp"
        android:layout_marginTop="30dp"
        android:contentDescription="@string/login_desc"
        android:scaleType="centerInside"
        fb:login_text=""
        fb:logout_text="" />

And in code I defined the background resource :

final LoginButton button = (LoginButton) findViewById(R.id.login_button);
button.setBackgroundResource(R.drawable.facebook);

Kind of a workaround, but I preferred this over changing Facebook SDK code (although it's very straight forward as well) and worry about updating each time I update the their version.

  • 78
Reply Report

yes if you want to change text and image both then write the below code.

authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setBackgroundResource(R.drawable.icon);
authButton.setText("Login");
authButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);`
  • 10
Reply Report

An other way

loginButton = (LoginButton) findViewById(R.id.fb_login_button);
loginButton.setVisibility(View.GONE);




ImageView ivFbCustomButton = (ImageView) findViewById(R.id.iv_fb_custom_button);
ivFbCustomButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        com.facebook.login.widget.LoginButton btn = new com.facebook.login.widget.LoginButton(FacebookActivity.this);
        btn.performClick();
    }
});

Note:

You have to write the code for two buttons in XML file. One is for default facebook button (We are hiding it at initial step). Second one is for custom button

  • 2
Reply Report