2

I'm trying to change the dimensions of my Facebook login button - however I'm only able to change the width of the button and for some reason the height always stays the same.

<com.facebook.login.widget.LoginButton
    xmlns:facebook="http://schemas.android.com/apk/res-auto"
    facebook:com_facebook_login_text="Log in with Facebook"
    android:id="@+id/login_button"
    android:layout_width="240dp"
    android:layout_height="50dp"
    android:layout_gravity="center_horizontal"/>

Any ideas why?

I have also tried putting the button in its own LinearLayout and setting both width and height to match_parent but again the height remains constant.

Grateful for any help!

iLearnAndr0id
  • 41
  • 1
  • 5
  • 1
    possible duplicate of [Facebook SDK v4 LoginButton ignores XML customizations](http://stackoverflow.com/questions/29446879/facebook-sdk-v4-loginbutton-ignores-xml-customizations) –  Jul 13 '15 at 19:10
  • I don't have the same LoginButton class as him – iLearnAndr0id Jul 13 '15 at 19:34
  • @iLearnAndr0id Yes you do - `com.facebook.login.widget.LoginButton`. Look beyond the first code block and you'll see... – Dev-iL Feb 10 '16 at 10:26
  • set paddingTop and paddingBottom,http://stackoverflow.com/a/32403046/2562861 – Shijil Aug 01 '16 at 10:38

3 Answers3

3

For Facebook SDK v4.x (or rather than using separate xml style)

The height of button is decided by its padding and textSize.

So if you want to increase button size, do it something like this

<com.facebook.login.widget.LoginButton
xmlns:facebook="http://schemas.android.com/apk/res-auto"
facebook:com_facebook_login_text="Log in with Facebook"
android:id="@+id/login_button"

android:textSize="15sp"
android:paddingTop="15sp" <!--increase more until it matches ur requirement -->
android:paddingBottom="15sp">

Hope it helps!!

Rafique Mohammed
  • 3,666
  • 2
  • 38
  • 43
0

You can create a custom button. To do this, create a custom style in your style.xml :

<style name="CustomFbButton">
<item name="android:background">THE IMAGE OF FB BUTTON</item>
<item name="android:layout_height">300dp</item>
<item name="android:layout_width">65dp</item>
<item name="android:layout_marginTop">If you need</item>
<item name="android:layout_marginBottom">If you need</item>
<item name="android:layout_gravity">center_horizontal</item> </style>

Now you can put into your xml (of your activity (where the button is)) :

<com.facebook.login.widget.LoginButton
xmlns:facebook="http://schemas.android.com/apk/res-auto"
facebook:com_facebook_login_text="Log in with Facebook"
android:id="@+id/login_button"
style="@style/CustomFbButton/>
nekflamm
  • 131
  • 12
  • Hi. Can you give me an example of how I could write a custom style for a button with 300dp width and 65dp height? And how I could use it in my code? – iLearnAndr0id Jul 14 '15 at 15:21
  • I didn't know you could customise buttons this way - thanks. However, I still have the same problem :( Everything works apart from the height. I increased text size which increased the button height, but the logo stayed the same size (small). Do you have any other suggestions? – iLearnAndr0id Jul 14 '15 at 16:53
  • I try just with that : And that worked. So without any custom style... May you have margin which block the size.. – nekflamm Jul 14 '15 at 17:10
0

Try this code using the code below. I used it and it worked for me.

<com.facebook.login.widget.LoginButton
xmlns:facebook="http://schemas.android.com/apk/res-auto"
facebook:com_facebook_login_text="Log in with Facebook"
android:id="@+id/login_button"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_gravity="center_horizontal"/>
Alfred Ayi-bonte
  • 715
  • 7
  • 11