Showing posts with label width. Show all posts
Showing posts with label width. Show all posts

Thursday, March 21, 2013

Android: Get screen width programmatically example

It returns number in pixel





      @SuppressLint("NewApi")
      private int getScreenWidth() {
            int iMeasuredwidth = 0;
            Point size = new Point();
            WindowManager w = getWindowManager();
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2){
                  w.getDefaultDisplay().getSize(size);
                  iMeasuredwidth = size.x;
            }else{
                  Display d = w.getDefaultDisplay();
                  iMeasuredwidth = d.getWidth();
            }
            return iMeasuredwidth;
      }


Monday, April 9, 2012

Android Dialog with default width

Having trouble making Dialog width to default length? (At least curtain length)

Use MinWidth theme:

final Dialog dialog = new Dialog(this, android.R.style.Theme_Holo_Dialog_MinWidth);
dialog.setContentView(R.layout.main);
dialog.setCancelable(true);
dialog.show();

You can also use: android.R.style.Theme_Holo_Light_Dialog_MinWidth