Estou fazendo as aulas do curso Android I: Crie sua App fantástica com Android Studio.
Na aula 3, sobre menus, não consigo criar o menu na activity com o formulário, crio o arquivo xml e inflo ele com o método posto no arquivo .java do formulário, mas quando vou ver, o menu está embaixo da textView nome.
Activity_formulario.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.example.eduardo.agenda.Formulario">
<include layout="@layout/content_formulario" />
</android.support.design.widget.CoordinatorLayout>
content_formulario.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_formulario"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<EditText
android:hint="Nome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nome"/>
<EditText
android:hint="Endereço"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/endereco"/>
<EditText
android:hint="Telefone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/telefone"/>
<EditText
android:hint="Site"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/site"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:max="10"
android:layout_gravity="center"/>
</LinearLayout>
</ScrollView>
Formulario.java:
package com.example.eduardo.agenda;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class Formulario extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulario);
}
@Override //método dos menus da toolbar
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_formulario, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.menForm:
Toast.makeText(Formulario.this, "Salvo", Toast.LENGTH_SHORT).show();
finish();
break;
default:
Log.d("INFO","##1default menu");
break;
}
return super.onOptionsItemSelected(item);
}
}
menu_formulario.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu 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"
tools:context="com.example.eduardo.agenda.MainActivity" >
<item android:id="@+id/menForm"
android:title="Save"
android:orderInCategory="100"
app:showAsAction="always" />
</menu>
Obs: a única preview que mostra o erro, é a preview da activity, logo acredito que seja nesta onde se encontra o problema. Exclui as tags que formavam a toolbox que vem na criação do arquivo.
Alguém saberia o que posso fazer para arrumar?