2016-10-22 16 views
0

サークルのfacebookとtwitterの画像を持つアプリを見ました。スクリーンショットを追加します enter image description hereアンドロイドのFacebookとGoogleログイン。カスタムボタンの形状

質問はどうやってfacebookボタンの円形を作ったのですか?私はスタンダードのfacebookボタンにカスタムテキストや背景イメージを追加する方法を知っています。

<com.facebook.login.widget.LoginButton 
      android:text="" 
      android:id="@+id/facebook_login_button" 
      android:layout_width="80dp" 
      android:layout_height="80dp" 
      android:background="@drawable/facebook_logo_button" 
      android:layout_gravity="center_horizontal" 
      /> 

しかし、私の結果は、私は enter image description here

+0

使用このライブラリます。https:// github.com/hdodenhof/CircleImageView –

+0

あなたは簡単なバットを作成することができますそのボタンをクリックすると、facebookやgoogleのコールを使用します。 – AmeeJoshi

+0

@Amee Joshiこれを行うには?私はfacebookボタン 'LoginButton loginButton =(LoginButton)view.findViewById(R.id.facebook_login_button)のためだけに利用可能ないくつかのメソッドがあることを意味します。 loginButton.setReadPermissions( "email"); loginButton.setFragment(this); ' – David

答えて

2

あなたはこのクラスを使用することができます期待したものと異なっている

public class Signup extends Activity{ 

    private AccessToken accessToken; 

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 


// If the access token is available already assign it. 
     accessToken = AccessToken.getCurrentAccessToken(); 


     btn_facebook = (Button) findViewById(R.id.facebook_button); 
     btn_facebook.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       if (AccessToken.getCurrentAccessToken() != null) { 
        // LoginManager.getInstance().logOut(); 
        LoginManager.getInstance().logInWithReadPermissions(SignUpOption.this, Arrays.asList("public_profile", "email", "user_friends")); 
       } else { 
        LoginManager.getInstance().logInWithReadPermissions(SignUpOption.this, Arrays.asList("public_profile", "email", "user_friends")); 
       } 
      } 
     }); 


      LoginManager.getInstance().registerCallback(callbackManager, 
       new FacebookCallback<LoginResult>() { 

        @Override 
        public void onSuccess(final LoginResult loginResult) { 

         AccessToken accessToken = AccessToken 
           .getCurrentAccessToken(); 

         GraphRequest request = GraphRequest.newMeRequest(
           loginResult.getAccessToken(), 
           new GraphRequest.GraphJSONObjectCallback() { 
            @Override 
            public void onCompleted(final JSONObject object, GraphResponse response) { 
             try { 
              id = object.optString("id").toString(); 
              fullName = object.optString("name").toString(); 
              String array[] = fullName.split(" "); 
              firstName = array[0].toString(); 
              lastName = array[1].toString(); 
              gender = object.optString("gender").toString(); 

              profilePicUrl = "https://graph.facebook.com/" + object.getString("id").toString() 
                + "/picture?type=large&return_ssl_resources=1"; 
              birthday = object.optString("birthday"); 
              try { 
               emailAddress = object.getString("email").toString(); 
              } catch (JSONException e) { 
               e.printStackTrace(); 
               emailAddress = ""; 
              } 


             } catch (Exception e) { 
              e.printStackTrace(); 
             } 
            } 
           }); 
         Bundle parameters = new Bundle(); 
         parameters.putString("fields", "id,name,email,gender, birthday"); 
         request.setParameters(parameters); 
         request.executeAsync(); 

        } 

        @Override 
        public void onCancel() { 
         AccessToken.setCurrentAccessToken(null); 
        } 

        @Override 
        public void onError(FacebookException exception) { 
         AccessToken.setCurrentAccessToken(null); 
         // Toast.makeText(SignUpOption.this, exception.getMessage(), Toast.LENGTH_LONG).show(); 
         ShowMsg(exception.getMessage()); 
        } 
       }); 

    } 


} 

デザインコード:

<view 
     android:id="@+id/facebook_button" 
     class="Utils.CustomButton" 
     android:layout_width="match_parent" 
     android:layout_height="45dp" 
     android:layout_marginTop="@dimen/dp_15" 
     android:textAllCaps="false" 
     android:background="@mipmap/fb_icon_big" 
     android:text="Sign-Up with Facebook" 
     android:textColor="@android:color/white" 
     android:gravity="center" 
     /> 
関連する問題