Android Custom dialog simple implementation method

  • 2021-01-19 22:26:25
  • OfStack

This article describes the Android custom dialog simple implementation method. To share with you for your reference, as follows:


@Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.function_music);
 //  Instantiate the new window 
 Window w = getWindow();
 //  Gets the default display data 
 Display display = w.getWindowManager().getDefaultDisplay();
 //  Gets the background image of the window 
 Resources resources = musicActivity.getResources();
 Drawable drawable = resources.getDrawable(R.drawable.operate_bg);
 //  Sets the background image of the window 
 w.setBackgroundDrawable(drawable);
 //  The title of the window is empty 
 w.setTitle(null);
 //  Define the width and height of the window 
 int width = (int) (display.getWidth() * 0.8);
 int height = (int) (display.getHeight() * 0.5);
 //  Sets the window size 
 w.setLayout(width, height);
 //  Sets the display position of the window 
 w.setGravity(Gravity.CENTER);
 //  Sets the properties of the window 
 WindowManager.LayoutParams wl = w.getAttributes();
 w.setAttributes(wl);
 //  Access controls 
 findView();
}

For more information on Android development, please check out the Android Introduction and Advanced Course.

I hope this article is helpful to Android program design.


Related articles: