System - Screen Information

//Screen Size

DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels;

//Screen Width In DP



//onButton
Context context = getApplicationContext();
textview1.setText("Screen width : " + getScreenWidthInDPs(context) + "dp");
textview1.setText(textview1.getText() + "
Screen height : " + getScreenHeightInDPs(context) + "dp");

//on new Block
public static int getScreenWidthInDPs(Context context){
android.util.DisplayMetrics dm = new android.util.DisplayMetrics();
android.view.WindowManager windowManager = (android.view.WindowManager) context.getSystemService(WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(dm);
int widthInDP = Math.round(dm.widthPixels / dm.density);
return widthInDP;
}
public static int getScreenHeightInDPs(Context context){
android.util.DisplayMetrics dm = new android.util.DisplayMetrics();
android.view.WindowManager windowManager = (android.view.WindowManager) context.getSystemService(WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(dm);
int heightInDP = Math.round(dm.heightPixels / dm.density);
return heightInDP;
}

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key