Home > Enterprise >  Make Image As Button With Link
Make Image As Button With Link

Time:04-01

in my .xml

<ImageView
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        android:layout_marginBottom="10dp"
        android:layout_weight="1"
        android:contentDescription="@ id/imageView11"
        app:srcCompat="@drawable/wa"
        tools:ignore="UsingOnClickInXml" />

enter image description here

How To Make This Image, to became Clickable and Redirect to some Url Thank You

CodePudding user response:

You can manage it with imageview.setOnClickListner same like button's click listner.

CodePudding user response:

You can also use the ImageButton class.

CodePudding user response:

If you want to share your link on whatsapp. Or share anything on whatsapp from your app then you can use this code to do.

First, add your ImageView to the ID. your id is whatsappBtn

<ImageView
        android:id="@ id/whatsappBtn"
        android:layout_width="20dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        android:layout_marginBottom="10dp"
        android:layout_weight="1"
        android:contentDescription="@ id/imageView11"
        app:srcCompat="@drawable/wa"
        tools:ignore="UsingOnClickInXml" />

and in your java code.

ImageView = whatsappBtn;
Uri yourUrl = yourLink // here your link

whatsappBtn = findViewById(R.id.whatsappBtn);

whatsappBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent goToWhatsapp = new Intent();
                        goToWhatsapp.setAction(Intent.ACTION_SEND);
                        goToWhatsapp.setPackage("com.whatsapp");
                        goToWhatsapp.setType("text/plain");
                        goToWhatsapp.putExtra(Intent.EXTRA_TEXT,yourLink);//Extra text
                        context.this.startActivity(goToWhatsapp); //context = your activity Name
            }
        });

If you have still a confusion. let me know

  • Related