当前位置:网站首页>Create dialog style windows with popupwindow

Create dialog style windows with popupwindow

2022-07-07 17:37:00 XLMN

Use popupwindow Create a dialog style window
public class MainActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popupwindow);
// load r.layout.popup The corresponding layout file
View root = this.getLayoutInflater().inflate(R.layout.popup, null);
// Create popupwindow object
final PopupWindow pw = new PopupWindow(root, 1560, 1720);
Button bt = findViewById(R.id.button2);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// The following pull mode shows
pw.showAsDropDown(v);
// take popupwindow Display in the specified location
pw.showAtLocation(findViewById(R.id.button2), Gravity.CENTER, 20, 20);
}
});
// obtain popupwindow Medium close button
root.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// close popupwindow
pw.dismiss();
}
});
}
}

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="560dp"
    android:src="@drawable/mia1" />

<Button
    android:id="@+id/close"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" close " />
<?xml version="1.0" encoding="utf-8"?>

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text=" eject popop window " />

 Insert picture description here

原网站

版权声明
本文为[XLMN]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071527553279.html