Reputation: 53
I cannot add action bar in my app it keeps on giving an error, moreover, when I add the toolbar it does not show anything in the layout
here is the screenshot of the code::
The full code is following...>>>>
package com.example.prateek.holachat;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toolbar;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private Toolbar mtoolBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
mtoolBar = (Toolbar) findViewById(R.id.toolBarNew);
setSupportActionBar(mtoolBar);
getSupportActionBar().setTitle("HOLA !");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main_menu,menu);
return true;
}
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
Intent startIntent = new Intent(MainActivity.this,StartActivity.class);
startActivity(startIntent);
finish();
}
}
}
And here is the screenshot of toolBar XML file..>>>
Upvotes: 0
Views: 1177
Reputation: 888
All the v7 libraries are used to support devices with old android versions. If you want to provide a the support use import android.support.v7.widget.Toolbar
with setSupportActionBar()
Otherwise as in your case you have import android.widget.Toolbar;
so use setActionBar()
instead.
Upvotes: 1