Skip to content

Instantly share code, notes, and snippets.

@yHori12
Last active August 6, 2019 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yHori12/abb9f01a92c965366ee81b1a175f878d to your computer and use it in GitHub Desktop.
Save yHori12/abb9f01a92c965366ee81b1a175f878d to your computer and use it in GitHub Desktop.
AndroidPopupWindow
<?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" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="#FF7F50"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:drawableLeft="@drawable/baseline_visibility_black_48dp"
android:gravity="center"
android:text="一行目"
android:layout_width="200dp"
android:layout_height="wrap_content"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFD700"/>
<TextView
android:drawableLeft="@drawable/baseline_accessibility_black_48dp"
android:gravity="center"
android:text="二行目"
android:layout_width="200dp"
android:layout_height="wrap_content"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FFD700"/>
<TextView
android:drawableLeft="@drawable/baseline_favorite_black_48dp"
android:gravity="center"
android:text="三行目"
android:layout_width="200dp"
android:layout_height="wrap_content"/>
</LinearLayout>
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener { button ->
val view = LayoutInflater.from(this).inflate(R.layout.content_popup, null)
val popupWindow = PopupWindow(view).apply {
isOutsideTouchable = true
isFocusable = true
}
popupWindow.showAsDropDown(button)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment