Search code examples
android-linearlayoutandroid-xmlandroidx

AndroidX Toolbar is mis-located


I am using AndroidX dependencies for my Android project.

I have a Toolbar in my activity (this activity is for supporting the developer by paying him some money) wrapped inside a linear layout like this:

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

The other XML codes used are as follows:

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

Now what I get is this:

Activity image


Solution

  • I got the answer to my own question!
    I had a line in my Support.java file:

    toolbar.bringToFront();
    

    I just removed it, and it helped me