09-20-2018, 07:49 AM
برای ایجاد رخداد کلیک برای ImageButton در Android Studio از متد زیر می توان استفاده کرد:
و کد XML کلید ایجاد شده به شرح ذیل می باشد:
کد:
ImageButton imageButton = (ImageButton)findViewById(R.id.IBtnNext);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// محل کد ها برای رخداد کلیک
}
});
و کد XML کلید ایجاد شده به شرح ذیل می باشد:
کد:
<ImageButton
android:id="@+id/IBtnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@android:drawable/ic_media_rew"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />