1

I'm trying to place a Like button in my app. After much searching I found that it is impossible to use me own custom button, so I am left only with implementing the default like button from the facebook sdk. Since this LikeView seems to be a native android like view I don't really know how to put this into my libGDX app.

I would like to use this button only in a specific Screen and set its bounds so that it fits with the rest of my UI. Does anyone have an example of how to create this like button without using the XML (as it is done in all the documentation I have found so far).

p.streef
  • 3,652
  • 3
  • 26
  • 50
  • Why would you even dare to say that it is impossible to create your own custom button? That seems like an odd comment to make. – Jay Snayder Jan 26 '15 at 13:27
  • posts like these: http://stackoverflow.com/questions/12032392/adding-custom-facebook-like-buttons-in-android – p.streef Jan 26 '15 at 13:55
  • Ah, I misread. I understood that you just wanted to create your own like button similar to Facebook (but not involving Facebook). You want to replace the Facebook one with one of your own. – Jay Snayder Jan 26 '15 at 15:22
  • Well, that was my first try, and it works with an og.likes post request but that doesn't accept facebook pages. So I'm stuck with having to use the LikeView button from the sdk. So what I need to know is how to use this LikeView with libgdx Screens. – p.streef Jan 26 '15 at 15:27

1 Answers1

2

Adding the following functions to my application makes it show in the correct position. Unfortunately the LikeView does not get the correct size, but is centered inside the view, which means changing the width/height just moves it.

public void GenerateLikeButton()
{
    application.runOnUiThread(new Runnable(){

        @Override
        public void run() {

            float x = 560 * game.global_scale;
            int width = (int) (440 * game.global_scale);
            int height = (int) (152* game.global_scale);
            float y_from_bottom = game.screen_height - ((56+152+70) * game.global_scale + game.ad_height);
            Gdx.app.log("like", "from bottom: "+ y_from_bottom);

            likeButton = new LikeView(application);
            likeButton.setLikeViewStyle(LikeView.Style.BUTTON);
            likeButton.setX(x);
            likeButton.setY(y_from_bottom-height);  

            likeButton.setObjectId(LIKE_URL);
            likeButton.setVisibility(View.GONE);
            application.layout.addView(likeButton,width,height);
            likeButton.invalidate();
        }
    });

}

@Override
public void ShowLikeButton(final boolean visible)
{
    application.runOnUiThread(new Runnable()
    {
        @Override
        public void run() 
        {
            if(visible)
                likeButton.setVisibility(View.VISIBLE);
            else
                likeButton.setVisibility(View.GONE);
        }
    });
}
p.streef
  • 3,652
  • 3
  • 26
  • 50