android - Android Studio:未出现 Google 登录按钮
问题描述
我正在关注如何在我的 Android 应用程序中实现谷歌身份验证的教程。我已经到了在我的 activity_login.xml 文件中添加谷歌预定义按钮的阶段,就像这里解释的那样:
<com.google.android.gms.common.SignInButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Login"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="50dp"/>
但是,预览中没有出现任何内容,除了按钮应该在的一行:
这是教程中的屏幕截图,用于解释它应该如何出现:
我已经按照教程中的说明仔细执行了每个步骤,所以我真的不明白为什么这不起作用。
主要是,我已将这些添加到依赖项中的 app/build.gradle 中:
implementation 'com.google.firebase:firebase-analytics:17.2.0' //Added for google authentication
implementation 'com.google.firebase:firebase-auth:19.2.0' //Added for google authentication
implementation 'com.google.android.gms:play-services-auth:17.0.0' //Added for google authentication
我已将其添加到依赖项中的 project/build.gradle 中:
classpath 'com.google.gms:google-services:4.3.2' // Added for authentication
知道为什么按钮没有出现吗?
编辑 1:根据要求,这里是整个 XML 代码:
PS:正常按钮出现正常。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.LoginActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/image_bg_login">
</ImageView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="26sp"
android:text="Things End. \n But memories last forever. \n Share your memories \n With the world"
android:textStyle="bold|italic">
</TextView>
</RelativeLayout>
<com.google.android.gms.common.SignInButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Login"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="50dp"/>
</FrameLayout>
</RelativeLayout>
解决方案
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@drawable/image_bg_login"
android:layout_height="match_parent"
tools:context=".Activity.LoginActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="26sp"
android:text="Things End. \n But memories last forever. \n Share your memories \n With the world"
android:textStyle="bold|italic"
tools:ignore="HardcodedText"/>
</RelativeLayout>
<com.google.android.gms.common.SignInButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Login"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="50dp"
tools:ignore="HardcodedText" />
</FrameLayout>
</RelativeLayout>
这是我得到的代码结果。
推荐阅读
- python-3.x - Paramiko - 重用现有的 SSH 句柄会导致 EOF 异常
- reactjs - 我的 userData 返回 undefined react js fetch
- json - 如何在 Swift 中从不同数据类型的 Json 数组创建模型?
- html - 使用 css 将外部笔画添加到文本中
- javascript - 使用递归检查元素是否为数组
- ruby-on-rails - Symbol 与 100 的比较失败
- date - 如何找到前几周的日期?
- r - 删除R中表格中的重复日期
- kubernetes - 有没有办法检测 Helm Chart 部署的资源所做的更改
- android - 如何区分多个用户的指纹?