在我的 .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" />
在此處輸入影像描述
如何制作此影像,使其可點擊并重定向到某些 URL 謝謝
uj5u.com熱心網友回復:
您可以使用imageview.setOnClickListner與按鈕的單擊串列器相同的方式對其進行管理。
uj5u.com熱心網友回復:
您也可以使用ImageButton該類。
uj5u.com熱心網友回復:
如果您想在 whatsapp 上分享您的鏈接。或從您的應用程式在 whatsapp 上分享任何內容,然后您可以使用此代碼來做。
首先,將您的 ImageView 添加到 ID。你的身份證是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" />
在你的java代碼中。
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
}
});
如果你還有困惑。讓我知道
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/454446.html
