1

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

Florian Monfort
  • 153
  • 4
  • 13
  • You've set the orientation to horizontal. And are you setting it as toolbar in `MyActivity.java`? – Thomas Vos May 31 '16 at 16:38
  • I see nowhere where it says it's horizontal, and isn't that the point of a horizontal navigation bar? Also why MyActivity.java? – Florian Monfort Jun 01 '16 at 04:40
  • Your LinearLayout is set to horizontal. That's why it is at the right and not the bottom. Here is an example for the toolbar: http://stackoverflow.com/a/30063604/4583267 – Thomas Vos Jun 01 '16 at 05:34

2 Answers2

1

For toolbar at the bottom,try like this

toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/primaryBlue"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context="com.ahotbrew.toolbar.MainActivity">

    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

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

        <TextView
            android:text="hello_brew"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </RelativeLayout>
</RelativeLayout>
prat
  • 597
  • 8
  • 17
1

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>
Muhammad Waleed
  • 2,517
  • 4
  • 27
  • 75
  • I've updated the post above using the solution from @prat, doesn't seem to do the trick, do you know what's wrong? – Florian Monfort Jun 01 '16 at 04:56
  • @FlorianMonfort try this github link https://github.com/DevLight-Mobile-Agency/NavigationTabBar – Muhammad Waleed Jun 01 '16 at 05:27
  • 1
    I'd rather not use a pre-built framework but learn how to do this myself, even if it's not as good – Florian Monfort Jun 01 '16 at 05:29
  • Figured it out! I looked at the differences and so it was not in the ToolBar XML part but the Relative Layout that it had to be set to vertical and not horizontal. Was not looking at the right code block. I think that's what you meant @Exception Lover – Florian Monfort Jun 01 '16 at 05:32
  • Yes sorry like I said, I didn't look at the right code block and did not see where your comment applied... my bad – Florian Monfort Jun 01 '16 at 07:59