Android: 'getWindowManager()' method error and solution
The method 'getWindowManager()' is a method of the 'android.view.Window' class, not the 'android.app.Activity' class. To access the 'getWindowManager()' method, you need to get a reference to the current window of the activity using the 'getWindow()' method and then call the 'getWindowManager()' method on the window object.
Here's an example of how to use 'getWindowManager()' in an activity:
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get a reference to the window
Window window = getWindow();
// Get the WindowManager from the window
WindowManager windowManager = window.getWindowManager();
// Use the WindowManager to perform operations on the window
// For example, get the display metrics:
DisplayMetrics metrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(metrics);
}
}
原文地址: https://www.cveoy.top/t/topic/ohAX 著作权归作者所有。请勿转载和采集!