Answer the question
In order to leave comments, you need to log in
android and toolbar?
I know that the question is not quite right, but anyway:
There is a toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_actionbar"
android:layout_width="match_parent"
app:theme="@style/AppTheme"
android:minHeight="?attr/actionBarSize"
android:layout_height="wrap_content"
android:background="@color/primary">
</android.support.v7.widget.Toolbar>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/search_bar"
android:title="@string/search"
android:orderInCategory="200"
android:showAsAction="always"
android:icon="@drawable/ic_search">
</item>
<item
android:id="@+id/navigation_bar"
android:title="@string/navigation"
android:orderInCategory="100"
android:showAsAction="always"
android:icon="@drawable/ic_nv_back">
</item>
</menu>
public class EnterActivity extends AppCompatActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.menu);
}
}
Answer the question
In order to leave comments, you need to log in
I would recommend inflating the menu in the Activity in the standard way, through onCreateOptionsMenu and onOptionsItemSelected , and then set your Toolbar as an ActionBar when creating the activity.
//Activity
setSupportActionBar((Toolbar) view.findViewById(R.id.toolbar));
//Fragment
((AppCompatActivity) getActivity()).setSupportActionBar((Toolbar) view.findViewById(R.id.toolbar));
Try like this:
<?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">
<item
android:id="@+id/search_bar"
android:title="@string/search"
android:orderInCategory="200"
app:showAsAction="always"
android:icon="@drawable/ic_search">
</item>
<item
android:id="@+id/navigation_bar"
android:title="@string/navigation"
android:orderInCategory="100"
app:showAsAction="always"
android:icon="@drawable/ic_nv_back">
</item>
</menu>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question