ActionBar with icon & title
When I want to replace the action bar with toolbar in all activities I would override setContentView() method in BaseActivity. It looks like this:
@Override
public void setContentView(@LayoutRes int layoutResID) {
super.setContentView(layoutResID);
View view = findViewById(R.id.toolbarContainer);
if (view != null) {
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
setTitle(getTitle());
}
}
Add Icon to the left of the title in the action bar in android
Recommended way
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_settings_24dp);// set drawable icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Handle icon click event
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Toast.makeText(this, "click..!!", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Show both logo and app name in action bar android
Solved adding
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.icona);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Using logo in actionbar is disabled by default in Android 5.0 Lollipop.
Related Topics
Nexus 5X Reverse Landscape Sensor Fix in a Android Camera Preview App
Disable Home Button in Android Ics (4.0)
Android Options Menu Icon Won't Display
Android 2.1 View's Getdrawingcache() Method Always Returns Null
Compatiblity of Material Design to Versions Below Android 5.0
Should Use "Sp" Instead of "Dp" for Text Sizes
How to Detect Android CPU Speed
Broadcast Receiver Not Working in Android Oreo
Single Click and Double Click of a Button in Android
Displaying Contact Number and Contact Name in a Custom List View
How to Use Asynctask to Display a Progress Bar That Counts Down
Configure Eclipse to Use Signed Keystore
Download and Extract Zip File in Android
How to Parse the CSV File in Android Application
Connectivity_Action Intent Received Twice When Wifi Connected