AndroidX工具栏位置错误

问题描述 投票:1回答:1

我正在为我的Android项目使用AndroidX依赖项。

我在我的活动中有一个Toolbar(这个活动是为了支持开发人员,通过支付他一些钱)包裹在这样的线性布局中:

<LinearLayout
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:orientation="vertical"
android:background="@drawable/gradient"
tools:context=".Support">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar_support"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@null"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

</LinearLayout>

使用的其他XML代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:background="@drawable/gradient"
tools:context=".Support">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar_support"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@null"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

<TextView
    android:layout_marginTop="150dp"
    android:layout_marginStart="10dp"
    android:layout_marginEnd="10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/google_sans"
    android:textSize="17dp"
    android:textColor="#ffffff"
    android:text="@string/support_para"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#ffffff"
        android:textSize="20dp"
        android:text="$"/>

    <EditText
        android:id="@+id/amount"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:hint="@string/pay_amount"
        android:textColorHint="#ffffff"
        android:textSize="20dp"
        android:layout_marginStart="10dp"
        android:layout_gravity="end"
        android:maxLines="1" />
</LinearLayout>

<Button
    android:id="@+id/googlepay"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="30dp"
    android:background="@drawable/round_button"
    android:textColor="#ffffff"
    android:fontFamily="@font/google_sans"
    android:text="@string/pay"/>

</LinearLayout>

现在我得到的是:

Activity image

android-linearlayout android-xml androidx
1个回答
0
投票

我得到了自己问题的答案! 我的Support.java文件中有一行:

toolbar.bringToFront();

我刚删除它,它帮助了我

© www.soinside.com 2019 - 2024. All rights reserved.