gpt4 book ai didi

android - 如何在Android中的自己的按钮上实现google plus登录功能

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:37 34 4
gpt4 key购买 nike

您好,我正在尝试学习 Android 中的 Google 登录功能。我这样做了,并且按预期工作得很好。

这里显示了 Google+ 的默认签名按钮,这是布局和屏幕截图。

<com.google.android.gms.common.SignInButton
android:id="@+id/loginGoogleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
/>

enter image description here

问题

我不想在我的按钮上使用这种样式。我想要一个像 android 那样的简单按钮

<Button
android:id="@+id/loginFaceboookButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/button_background"
android:text="@string/login_with_facebook"
android:textColor="@android:color/white" />

该按钮如何实现 Google 登录功能或如何使 com.google.android.gms.common.SignInButton 成为 android 中的简单默认按钮。

提前致谢。

最佳答案

抛开法律问题,SignInButton 实际上不执行任何特殊功能,它只是一个可视化小部件。来自docs :

The Google sign-in button to authenticate the user. Note that this class only handles the visual aspects of the button. In order to trigger an action, register a listener using setOnClickListener(OnClickListener).

也就是说,如果您有一个正在运行的 Google+ 示例(即使用 GoogleApiClient、相关回调、来自 com.google.android.gms.plus 的任何 API 等),那么您可以替换 SignInButton与任何其他常规按钮一起使用,它的工作原理是一样的。


关于示例代码:抱歉,根据您问题的措辞,我假设您已经运行了这部分。

您可以找到 G+ 集成教程 here , 特别是 this是关于登录的部分。此外,示例项目作为 SDK (<android-sdk>\extras\google\google_play_services\samples\plus) 的一部分分发,一切准备就绪(尽管您需要在 Google Developers Console 中启用 API,如链接中所述,以使其正常工作)。

然后你可以交换 SignInButton对于常规按钮。

关于android - 如何在Android中的自己的按钮上实现google plus登录功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27202306/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com