Using custom login button with Twitter Fabric?

前端 未结 5 1870
名媛妹妹
名媛妹妹 2021-01-31 04:27

I have been trying to use a normal button to execute the authentication process with the twitter sdk but it does not seem to work. Anyone have tried anything similar?

5条回答
  •  粉色の甜心
    2021-01-31 05:03

    Since Fabric doesn't allow theming yet, we should assume that we'll have to write potentially throw away code to get this to work. As such, I prefer less code to more code when I know I won't be keeping it.

    Luis's solution will work fine, but my UI was done, with a button already, and I just wanted that button to work. Here's how I accomplished this.

    Drop in the TwitterLoginButton, as requested by the Fabric wizard, but set it to visibility: gone

     
    

    Pull the reference of the loginButton in your Activity (also part of Fabric setup - nothing new here):

    loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
    

    Finally, for my existing button, I added a click listener, which simply delegated the click event over to the twitter login button.

    myLoginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loginButton.performClick();
            }
        });
    

    Worked like a charm.

提交回复
热议问题