如何在android中使用facebook sdk 4.7.0和自定义Google Plus登录按钮创建自定义facebook登录按钮
我正在使用facebook登录和google plus登录构建一个android应用程序。我发现很难为这两个定制按钮。有办法改变吗 我正在使用AndroidStudio 1.4,并使用gradle依赖项添加g+和fb登录,如下所示如何在android中使用facebook sdk 4.7.0和自定义Google Plus登录按钮创建自定义facebook登录按钮,android,android-studio,gradle,facebook-login,google-plus-signin,Android,Android Studio,Gradle,Facebook Login,Google Plus Signin,我正在使用facebook登录和google plus登录构建一个android应用程序。我发现很难为这两个定制按钮。有办法改变吗 我正在使用AndroidStudio 1.4,并使用gradle依赖项添加g+和fb登录,如下所示 dependencies { compile 'com.google.android.gms:play-services:8.1.0' compile 'com.google.android.gms:play-services-identity:8.1.0' com
dependencies
{
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}
可绘图文件夹中的fblogin\u button\u selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<solid android:color="@color/com_facebook_button_background_color_pressed" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<solid android:color="@color/com_facebook_button_background_color" />
</shape>
</item>
</selector>
在布局中自定义FB登录按钮
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/login"
android:layout_centerHorizontal="true"
android:paddingStart="@dimen/dp_50"
android:paddingLeft="@dimen/dp_50"
android:drawableLeft="@drawable/com_facebook_button_icon"
android:textSize="@dimen/sp_15"
android:background="@drawable/com_facebook_button_background"
android:text="Connect "
android:textColor="@android:color/white"/>
输出:
使用此选项,您还可以在drawable文件夹中实现G+登录按钮。fblogin\u Button\u selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<solid android:color="@color/com_facebook_button_background_color_pressed" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<solid android:color="@color/com_facebook_button_background_color" />
</shape>
</item>
</selector>
在布局中自定义FB登录按钮
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/login"
android:layout_centerHorizontal="true"
android:paddingStart="@dimen/dp_50"
android:paddingLeft="@dimen/dp_50"
android:drawableLeft="@drawable/com_facebook_button_icon"
android:textSize="@dimen/sp_15"
android:background="@drawable/com_facebook_button_background"
android:text="Connect "
android:textColor="@android:color/white"/>
输出:
使用此功能,您还可以实现G+登录按钮。对于我来说,此解决方案有效 xml上的按钮
<com.facebook.login.widget.LoginButton
android:id="@+id/button_facebook"
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/transparent"
style="@style/FacebookLoginButton"
android:longClickable="false" />
更改style.xml
<style name="FacebookLoginButton">
<item name="android:textSize">16sp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_gravity">center_horizontal</item>
</style>
16便士
10dp
10dp
水平中心
对我来说,这个解决方案很有效
xml上的按钮
<com.facebook.login.widget.LoginButton
android:id="@+id/button_facebook"
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/transparent"
style="@style/FacebookLoginButton"
android:longClickable="false" />
更改style.xml
<style name="FacebookLoginButton">
<item name="android:textSize">16sp</item>
<item name="android:layout_marginTop">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:layout_gravity">center_horizontal</item>
</style>
16便士
10dp
10dp
水平中心
请发布一些图片或链接到您想要的自定义按钮的线框或模型。”“上面的图片是我想要实现的,下面是我目前正在实现的@vipul_asr请发布一些图片或链接到您想要的自定义按钮的线框或模型。”“上面的图片是我想要实现的,下面是我目前在@vipul_asrii使用此按钮时实现的目标,我可以使用默认按钮吗@毒蛇_asri@NilabjaMukherjee不,我尝试过使用默认按钮对其进行自定义,但它没有太大的灵活性,无法完全按照您的要求进行定制。凯,感谢您的帮助,稍后将尝试实现它@vipul_asrii正在使用此按钮,我可以使用默认按钮吗@毒蛇_asri@NilabjaMukherjee不,我尝试过使用默认按钮来定制它,但它没有太多的灵活性,无法完全按照您的要求进行定制。Kay,感谢您的帮助,稍后将尝试实现@vipul_asrith此操作非常有效,但我需要自定义背景,因此必须使用选择器我理解您的选择,使用选择器,您可以更改背景@Nilabjamukherjee这很好,但我需要自定义背景,所以必须使用选择器。我理解您的选择,使用选择器您可以更改背景@尼拉布贾穆克吉