首页 > 解决方案 > 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>

标签: androidxmlandroid-studio

解决方案


在此处输入图像描述试试这个,这是我得到的代码结果。''

   <?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>

这是我得到的代码结果。


推荐阅读