The image I used to make the tests is a simple 100x100 size gear with the transparent background.
FirstofallInoticedthatunlikeButton,whencreatinganImageButtonyouareobligedtoaddanimagetoit:
Notethatifnoimageisselected,itscreationisdisabled(whichmakesperfectsense).
IselectedanimagesothatIcouldcreatetheImageButtonandsoonrealizedthatbehindtheimage(gear)appearsa"gray stop" covering all its background:
Butwhat'sup?That'sit?Icouldverymuchaddabackgroundtoanormalbuttonanditwouldhavethesameeffect,aswellasnothavingthat" useless gray stop " behind.
Followingthetests=>WhenIincreasedthesizeoftheButtonfrom100x100to150x150,obviouslythequalityoftheimageresolutiondecreased,butdoingsowiththeImageButtonthesizeofthegearremainedthesameandwhatincreasedwasthe" strong> "behind the image:
OnemorethingthathappensintheButtonthatdoesnothappenintheImageButton,isthatwhenyousetthebackgroundoftheButton,ifithassometextanditisnotremoved,itkeepsappearing,withtheimage:
InfavoroftheImageButton(dependingontheneed)Inoticedthatclickingonit,thereisaneffectontheclick.It'ssimple,butthere's:
IntheButtonthereisalsothiseffect,butonlywhennobackgroundissetinit.
InMainActivitythedeclarationanduseofbothisthesame:
package genesysgeneration.classsound;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button button;
private ImageButton imageButton2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button);
imageButton2=(ImageButton)findViewById(R.id.imageButton2);
button.setOnClickListener(this);
imageButton2.setOnClickListener(this);
}
public void onClick(View v){
switch (v.getId()){
case R.id.button:
Intent it01 = new Intent(this, Main2Activity.class);
startActivity(it01);
break;
case R.id.imageButton2:
Intent it02 = new Intent(this, Main2Activity.class);
startActivity(it02);
break;
}
}
}