Don't Miss

Display image in activity android

By on January 10, 2018

Activity.java

*** First copy the image and paste  into res/drawable

 

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class ExampleActivity extends AppCompatActivity {

private ImageView imgImageView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imgImageView = (ImageView)findViewById(R.id.image);

imgImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Toast.makeText(ExampleActivity.this, “Image Tapped”, Toast.LENGTH_SHORT).show();
}
});

}

}

 

activity_main.xml

 

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>

<ImageView
android:id=”@+id/image”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/background”/>

</RelativeLayout>

 

About CodingBazz

Leave a Reply

Your email address will not be published. Required fields are marked *