i have a toolbar which include one button, how to implement onclick function for this button?
this is my way to create the toolbar and button.
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_bottom"
android:layout_width="match_parent"
android:background="#2196F3"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:layout_gravity="left"
/>
</android.support.v7.widget.Toolbar>
this is the function call in MainActivity
Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom);
toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()){
case R.id.test:
Toast.makeText(MainActivity.this,"asdasd",Toast.LENGTH_SHORT).show();
}
return true;
}
});