-1

Let me know if you can see my link without logging in below. The problem I am having is the same as the person described. The blue action bar is blocking the name of my app in every project I create. I haven't seen anyone with this problem other than the person who posted the discussion. Please help me out if you can, I appreciate it.

-Timmy

<?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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="16dp"
        android:paddingBottom="16dp"
        android:text="Quantity"
        android:textAllCaps="true"/>

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

        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_marginBottom="16dp"
            android:onClick="minusIncrement"
            android:text="-"/>

        <TextView
            android:id="@+id/quantity_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:text="2"
            android:textColor="@android:color/black"
            android:textSize="16sp"/>

        <Button
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_marginBottom="16dp"
            android:onClick="plusIncrement"
            android:text="+"/>

    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="16dp"
        android:text="Price"
        android:textAllCaps="true"/>

    <TextView
        android:id="@+id/price_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="16dp"
        android:text="$10"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:onClick="submitOrder"
        android:text="Order"/>
</LinearLayout>

package com.example.android.justjava;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toolbar;

import java.text.NumberFormat;

/**
 * This app displays an order form to order coffee.
 */
public class MainActivity extends AppCompatActivity {

    int quantity = 2;

    /**
     * This method displays the given text on the screen.
     */

    private void displayMessage(String message) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
        priceTextView.setText(message);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /**
     * This method is called when the order button is clicked.
     */
    public void submitOrder(View view) {
     String priceMessage = "Total: $" + (quantity * 5);
        priceMessage = priceMessage + "\nThank you!";
        displayMessage(priceMessage);
    }

    /**
     * This method is called when the plus button is clicked.
     */
    public void plusIncrement(View view) {
        quantity = quantity + 1;
        display(quantity);
    }

    /**
     * This method is called when the minus button is clicked.
     */
    public void minusIncrement(View view) {
        quantity = quantity - 1;
        display(quantity);
    }

    /**
     * This method displays the given quantity value on the screen.
     */
    private void display(int number) {
        TextView quantityTextView = (TextView) findViewById(
                R.id.quantity_text_view);
        quantityTextView.setText("" + number);
    }

    /**
     * This method displays the given price on the screen.
     */
    private void displayPrice(int number) {
        TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
        priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
    }
}

https://discussions.udacity.com/t/title-on-the-app-is-not-showing/37056

timmyspan
  • 77
  • 1
  • 11
  • http://stackoverflow.com/questions/2591036/how-to-hide-the-title-bar-for-an-activity-in-xml-with-existing-custom-theme before setContentView(...) – Burak Karasoy Nov 13 '15 at 00:33
  • 1
    Will you please post the .java files and the .xml files for the activities you are having issues with? I have an idea of what's happening but I need to see your code. – Sloganho Nov 13 '15 at 00:34
  • first of all, don't link your question to somewhere else that requires login to view the post. Second, show what you have tried. – Saehun Sean Oh Nov 13 '15 at 01:00
  • burak Karasoy your link did not help me, thanks for the down vote you degenerate. Sloganho I am having trouble posting but the code will be up soon. Saehun Sean Oh I asked earlier to let me know if you can't see it so thank you for already telling me a problem I thought would happen. – timmyspan Nov 13 '15 at 01:03

1 Answers1

0

When working with the toolbar you have to do things a little different. You can do this:

MainActivity.java

public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if(toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("My custom toolbar!");
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
 }

}

activity_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="match_parent"
tools:context=".MainActivity">

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:background="@android:color/holo_red_light"
    android:minHeight="100dp">

</android.support.v7.widget.Toolbar>

</RelativeLayout>

So the big issue is that the ToolBar is never added to the current content view and hence will never be visible until you actually add the ToolBar to the current content view.

The answer taken from here: Title, etc. not showing in Android Toolbar

Sachin Bahukhandi
  • 2,378
  • 20
  • 29
Sloganho
  • 2,041
  • 3
  • 16
  • 20
  • setSupportActionBar(toolbar); is saying that it can't be applied to android.widget.Toolbar – timmyspan Nov 13 '15 at 01:17
  • Error:(35, 37) error: incompatible types: android.widget.Toolbar cannot be converted to android.support.v7.widget.Toolbar – timmyspan Nov 13 '15 at 01:20
  • Make sure that you're using v7 for everything then. Make sure this is what's being imported in your Main.activity: import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; – Sloganho Nov 13 '15 at 01:21
  • Okay i will give it a shot, thanks a lot for being so helpful. – timmyspan Nov 13 '15 at 01:27
  • If it doesn't work, let me know and I can continue to help. – Sloganho Nov 13 '15 at 01:27
  • When I set the title it says it may produce 'java.lang.NullPointerException' But when I ran it, I got the correct display with my app name showing. Does that little blurb affect me at all? – timmyspan Nov 13 '15 at 01:36
  • You should be fine if you have it surrounded with the if(toolbar != null) – Sloganho Nov 13 '15 at 01:44