Florian Monfort Florian Monfort - 6 months ago 21
Android Question

Toolbar does not appear android

I am trying to play around with some Android code for the first time. I have been following at the beginning the Hello World example until when you create a text input and then launch a different Activity and send the text input content activity by pressing the send button.

Now I want to add a bottom ToolBar for navigation so I implement an empty activity that is separate to define the toolbar and that I then in my main activity. But as you can see no toolbar actually appears however my text input itself has disappeared and my send button now appears somewhere else... I don't really know what I am doing to be honest so if I could get some explanation I would highly appreciate it:

UPDATE: I have tried the solution from @prat see the new screenshots attached.

UPDATE 2: solved by setting the relativelayout to vertical instead of horizontal.

enter image description here

enter image description here

Ultimately what I am trying to achieve is a bar that resembles the updated navbar at the bottom from Google's Material Design guidelines:

enter image description here

Answer

For bottom toolbar.try this code.

<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="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:layout_alignParentBottom="true"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello_android" />
    </RelativeLayout>
</RelativeLayout>