<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:layoutDirection="rtl" android:orientation="vertical" android:textDirection="rtl"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingBottom="10dp" android:paddingEnd="40dp" android:paddingTop="10dp"> <android.support.v7.widget.AppCompatImageView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginStart="4dp" app:srcCompat="@drawable/ic_share_gray_24dp" /> <android.support.v7.widget.AppCompatTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:gravity="center_vertical" android:text="@string/share" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingBottom="10dp" android:paddingEnd="40dp" android:paddingTop="10dp"> <android.support.v7.widget.AppCompatImageView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginStart="4dp" app:srcCompat="@drawable/ic_delete_gray_24dp" /> <android.support.v7.widget.AppCompatTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:gravity="center_vertical" android:text="@string/delete" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingBottom="10dp" android:paddingEnd="40dp" android:paddingTop="10dp"> <android.support.v7.widget.AppCompatImageView android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginStart="4dp" app:srcCompat="@drawable/ic_create_new_folder_gray_24dp" /> <android.support.v7.widget.AppCompatTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:gravity="center_vertical" android:text="@string/move_to_folder" /> </LinearLayout> </LinearLayout>
fun imageButtonMoreVert_OnClick(v: View) { val view = layoutInflater.inflate(R.layout.gallery_selection_menu, null) val popup = PopupWindow(this) popup.contentView = view popup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT); popup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); popup.setFocusable(true); val location = IntArray(2) imageButtonMoreVert.getLocationOnScreen(location) val p = Point(location.get(0), location.get(1)) val OFFSET_X = -20 val OFFSET_Y = 50 popup.showAtLocation(view, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y); }
References
https://stackoverflow.com/questions/15454995/popupmenu-with-icons
https://androidresearch.wordpress.com/2012/05/06/how-to-create-popups-in-android/