add icon/logo of the app to action bar in Android in Android Studio


1- First if you don't add icon/logo to you app yet the android studio add the default icon/logo and if you need to add a new one go to:


 


The when the window of the Asset Studio open, in the Icon Type check if the type is: Launcher Icons(Adaptive and Legacy) and add the path of the logo or the icon.


2- then, Go to the file control .java in Java folder, and add after the:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

if the xml or layer named main, so add after it this lines:

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
 
You need to add in the part of " import " or in the top of the file this line (edit the line like the app maked):

import static com.xxxxx.xxxxxx.R.mipmap.ic_launcher;
 
3- then test it.

if any problem write a comment bellow.
 
 

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel