skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search