Android examples for User Interface:Toast
Displays a toast message stating the screen size.
//package com.java2s; import android.content.Context; import android.content.res.Configuration; import android.widget.Toast; public class Main { public final static String[] SCREEN_SIZES = { "small", "normal", "large", "xlarge", "unknown" }; /**// w w w.j a va2 s . c om * Displays a toast message stating the screen size. One of five options: * small, normal, large, xlarge, and unknown * * @param context */ public static void showScreenSize(Context context) { Configuration config = context.getResources().getConfiguration(); int layout = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; String size = "unknown"; switch (layout) { case Configuration.SCREENLAYOUT_SIZE_SMALL: size = SCREEN_SIZES[0]; break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: size = SCREEN_SIZES[1]; break; case Configuration.SCREENLAYOUT_SIZE_LARGE: size = SCREEN_SIZES[2]; break; // We do 4 here for devices lower than API 9. (4 is the static // number of xlarge) case 4: size = SCREEN_SIZES[3]; break; default: size = SCREEN_SIZES[4]; } Toast.makeText(context, "Screen Size: " + size, Toast.LENGTH_LONG) .show(); } }