I am new to the world of mobile programming and I had a problem when creating a toolbar in the java code, this does not recognize the object created with the name toolbar in setSupportActionBar (toolbar), here is the code:
package com.example.jayrosalazar.platzigram.view;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toolbar;
import android.support.v7.app.ActionBar;
import com.example.jayrosalazar.platzigram.R;
public class CreatAccountActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_creat_account);
showToolbar(getResources().getString(R.string.toobar_tittle_createaccount),false);
}
//Método para visualizar y crear un Toolbar
public void showToolbar(String tittle, boolean upButton){
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar) //Declaramos un objeto tipo Toolbar y lo instanciamos
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(tittle);
getSupportActionBar().setDisplayHomeAsUpEnabled(upButton);
}
}
Here is the layout in xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
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:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>