首页 > 解决方案 > 改成RelativeLayout后导航栏消失

问题描述

我的 AndroidStudio 使用 ConstraintLayout 作为默认布局,我在 XML 代码中将其更改为 RelativeLayout。最后,我再次放置了我需要的所有 UI。在其他活动中,布局仍然是 ConstraintLayout。我的计划是稍后将它们也更改为 RelativeLayout。

更改后我的问题是,Android 的导航栏消失了。见图片。 在此处输入图像描述

我的 XML 代码是:

<?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"
android:background="#FFFFFF"
tools:context=".MainActivity">


<EditText
    android:id="@+id/passwordField"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:hint="@string/password"
    android:ems="10"
    android:inputType="numberPassword"
     />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_alignParentTop="true"
    android:text="@string/login"
    android:textSize="36sp"
    />

<Button
    android:id="@+id/logInButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_centerInParent="true"
    android:layout_below="@id/checkBox"
    android:onClick="logIn"
    android:text="@string/log_in"
     />

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_below="@id/passwordField"
    android:onClick="showPassword"
    android:text="@string/show_password"
    />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_below="@+id/logInButton"
    android:onClick="createNewAccount"
    android:layout_centerInParent="true"
    android:text="@string/create_account"
     />

<TextView
    android:id="@+id/textForgotPassword"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:textSize="18sp"
    android:onClick="forgotPassword"
    android:text="@string/forgot_the_password_click_here" />


</RelativeLayout>

有人可以告诉我我做错了什么吗?

先感谢您!

标签: androidxmlandroid-studioandroid-layoutlayout

解决方案


推荐阅读