This video show how to apply Android provided Material Theme to your Activity.
- Edit values/styles.xml to add a new style inherits from Android provided Material Theme: android:Theme.Material, android:Theme.Material.Light or android:Theme.Material.Light.DarkActionBar.
- Edit AndroidManifest.xml to use the new style.
- You have to change your MainActivity extends Activity. Otherwise the following error will happen: You need to use a Theme.AppCompat theme (or descendant) with this activity. The video also show how it display on Multi-Window Mode.
The class android.util.DisplayMetrics is a structure describing general information about a display, such as its size, density, and font scaling. Here show how to get display information (specially heightPixels and widthPixels) in Multi-Window Mode.
if(isInMultiWindowMode()){ textPrompt.setText("onCreate run In Multi Window Mode "); }else{ textPrompt.setText("onCreate run NOT In Multi Window Mode "); }
private void showDisplayInfo(){ DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm);
String strScreenDIP = ""; strScreenDIP += "The logical density of the display: " + dm.density + "\n"; strScreenDIP += "The screen density expressed as dots-per-inch: " + dm.densityDpi +"\n"; strScreenDIP += "The absolute height of the display in pixels: " + dm.heightPixels +"\n"; strScreenDIP += "The absolute width of the display in pixels: " + dm.widthPixels + "\n"; strScreenDIP += "A scaling factor for fonts displayed on the display: " + dm.scaledDensity + "\n"; strScreenDIP += "The exact physical pixels per inch of the screen in the X dimension: " + dm.xdpi + "\n"; strScreenDIP += "The exact physical pixels per inch of the screen in the Y dimension: " + dm.ydpi + "\n";
if(isInMultiWindowMode()){ textPrompt.setText("onCreate run In Multi Window Mode "); }else{ textPrompt.setText("onCreate run NOT In Multi Window Mode "); }
This example show how to detect and check if your app run in multi window mode, target Android N with Multi-Window Support, by calling isInMultiWindowMode() and override onMultiWindowModeChanged() methods.
if(isInMultiWindowMode()){ textPrompt.setText("onCreate run In Multi Window Mode "); }else{ textPrompt.setText("onCreate run NOT In Multi Window Mode "); } }
@Override public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { super.onMultiWindowModeChanged(isInMultiWindowMode);
if(isInMultiWindowMode){ textPrompt.setText("It is In Multi Window Mode "); }else{ textPrompt.setText("It is NOT In Multi Window Mode "); } } }