In writing the project is faced with this situation. I have several activations and in each of them there is a toolbar of the same type. I do not want to prescribe the same strings in each of them, and therefore I created the abstract class BaseActivity. The onCreate method in it works perfectly, but for some reason, the onCreateOptionsMenu method does not want to show me my 3 right icons in each of the activations inherited from BaseActivity. This method is just null! Is there another way to create a menu, or does something need to be added so that the icons show up after all? The menu itself was created in the classical way - through a drawable with writing item. Abstract class code:
import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; public abstract class BaseActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu, menu); return super.onCreateOptionsMenu(menu); } }
findViewById(R.id.toolbar)
layout has not yet been set (there was no call tosetContentView(...)
- therefore the toolbar was not found and not installed. - woesss