Android 安卓facebook和谷歌登录。自定义按钮形状

Android 安卓facebook和谷歌登录。自定义按钮形状,android,facebook,imageview,Android,Facebook,Imageview,我在应用程序上看到了facebook和twitter的圆形图片。我将添加屏幕截图 问题是他们是如何制作facebook按钮圆形的?我知道如何在standart facebook按钮上添加自定义文本或背景图像 <com.facebook.login.widget.LoginButton android:text="" android:id="@+id/facebook_login_button" android:

我在应用程序上看到了facebook和twitter的圆形图片。我将添加屏幕截图

问题是他们是如何制作facebook按钮圆形的?我知道如何在standart 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"
          />

但我的结果与我预期的不同
您可以使用这个类

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());
                    }
                });

  }


}
公共类注册扩展了活动{
专用AccessToken AccessToken;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//如果访问令牌可用,则已分配它。
accessToken=accessToken.getCurrentAccessToken();
btn_facebook=(按钮)findviewbyd(R.id.facebook_按钮);
btn_facebook.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
if(AccessToken.getCurrentAccessToken()!=null){
//LoginManager.getInstance().logOut();
LoginManager.getInstance().logInWithReadPermissions(SignUpOption.this,Arrays.asList(“public\u profile”,“email”,“user\u friends”));
}否则{
LoginManager.getInstance().logInWithReadPermissions(SignUpOption.this,Arrays.asList(“public\u profile”,“email”,“user\u friends”));
}
}
});
LoginManager.getInstance().registerCallback(callbackManager,
新建FacebookCallback(){
@凌驾
成功时公开作废(最终登录结果登录结果){
AccessToken AccessToken=AccessToken
.getCurrentAccessToken();
GraphRequest请求=GraphRequest.newmereRequest(
loginResult.getAccessToken(),
新建GraphRequest.GraphJSONObjectCallback(){
@凌驾
未完成公共void(最终JSONObject对象,GraphResponse响应){
试一试{
id=object.optString(“id”).toString();
fullName=object.optString(“name”).toString();
字符串数组[]=fullName.split(“”);
firstName=array[0]。toString();
lastName=数组[1]。toString();
gender=object.optString(“gender”).toString();
profilePicUrl=”https://graph.facebook.com/“+object.getString(“id”).toString()
+“/picture?type=large&return\u ssl\u resources=1”;
生日=object.optString(“生日”);
试一试{
emailAddress=object.getString(“电子邮件”).toString();
}捕获(JSONException e){
e、 printStackTrace();
电子邮件地址=”;
}
}捕获(例外e){
e、 printStackTrace();
}
}
});
Bundle参数=新Bundle();
参数.putString(“字段”、“id、姓名、电子邮件、性别、生日”);
请求。设置参数(参数);
request.executeAsync();
}
@凌驾
公开作废{
AccessToken.setCurrentAccessToken(空);
}
@凌驾
public void onError(facebook异常){
AccessToken.setCurrentAccessToken(空);
//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"
       />

您可以使用该类

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());
                    }
                });

  }


}
公共类注册扩展了活动{
专用AccessToken AccessToken;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//如果访问令牌可用,则已分配它。
accessToken=accessToken.getCurrentAccessToken();
btn_facebook=(按钮)findviewbyd(R.id.facebook_按钮);
btn_facebook.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
if(AccessToken.getCurrentAccessToken()!=null){
//LoginManager.getInstance().logOut();
LoginManager.getInstance().logInWithReadPermissions(SignUpOption.this,Arrays.asList(“public\u profile”,“email”,“user\u friends”));
}否则{
LoginManager.getInstance().logInWithReadPermissions(SignUpOption.this,Arrays.asList(“public\u profile”,“email”,“user\u friends”));
}
}
});
LoginManager.getInstance().registerCallback(callbackManager,
新建FacebookCallback(){
@凌驾
成功时公开作废(最终登录结果登录结果){
AccessToken AccessToken=AccessToken
.getCurrentAccessToken();
GraphRequest请求=GraphRequest.newmereRequest(
loginResult.getAccessToken(),