'Make Image As Button With Link
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" />
How To Make This Image, to became Clickable and Redirect to some Url Thank You
Solution 1:[1]
You can manage it with imageview.setOnClickListner same like button's click listner.
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bhoomika Patel |
| Solution 2 | M Dev |
