Last active
August 6, 2019 11:59
-
-
Save yHori12/abb9f01a92c965366ee81b1a175f878d to your computer and use it in GitHub Desktop.
AndroidPopupWindow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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