title: Android how to force screen density by default
body: <p>By magnifying the screen by "Settings / Displays",  I've found that my galaxy s9+'s screen density changes to 430 dpi to somewhere over 600dpi. </p>
  
  <p>This makes the layout and images to change to xxhdpi to xxxhdpi. </p>
  
  <p>If I have a textView which has the fixed size of 16dp,</p>
  
  <p>it was 16 * 3 px in xxhdpi, and will become 16 * 4 px in xxxhdpi.</p>
  
  <p>This makes my layout(of course texts from editTexts or textViews) to become much bigger since the actual density of the device never changes, which google(or the maker samsumg) intended for this function.</p>
  
  <p>But I do not want this to happen in my app.</p>
  
  <p>I've tried to fix it by doing this ;</p>
  
  <pre><code>Configuration configuration = activity.getResources().getConfiguration();
  
  if (configuration.densityDpi != 430) { 
                  configuration.densityDpi = 430;    
  }
  
  DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
  WindowManager wm = (WindowManager) activity.getSystemService(activity.WINDOW_SERVICE);
  wm.getDefaultDisplay().getMetrics(metrics);
  metrics.scaledDensity = configuration.densityDpi * metrics.density;
  activity.getResources().updateConfiguration(configuration, metrics);
  </code></pre>
  
  <p>This forces the screen density to become 430 and works fine on galaxy s9+. 
  But, as a matter of fact, the default density will not be 430 for all devices. </p>
  
  <p>How can I figure out the default density of the device which runs my application? </p>
  
  <p>Or is there a configuration to ignore the magnify effect for my application? </p>