Archive

Archive for December, 2009

How to set icon for title bar in Android?

December 8, 2009 1 comment

In android we have the facility to set a icon for title bar.

see the below image here the title bar contains only title.
Title name is Iconic Memorey

How to set icon in title bar?.
use this.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_RIGHT_ICON);
setContentView(R.layout.main);
setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.icon);
}

By using this code we can get the output like below image

Advertisements

How to hide the title bar in Android?

December 8, 2009 Leave a comment

When we develop a game or some other application, we may need to show a full page(screen) for users.

See the below image, In that Alarm Clock is the title showing in title bar.

To remove this title bar we need to use,


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
}

After this,

Now the title bar will be removed.

How to get the screen size in Android?

December 8, 2009 Leave a comment

Android screen size is different from different phone models.

There are some screen resolutions defined in android.

They are:

  • QVGA (240×320, low density, small screen)
  • WQVGA (240×400, low density, normal screen)
  • FWQVGA (240×432, low density, normal screen)
  • HVGA (320×480, medium density, normal screen)
  • WVGA800 (480×800, high density, normal screen)
  • WVGA854 (480×854 high density, normal screen)

Now we can see how to get the screen size ,


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

int h;
int w;

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
h = displaymetrics.heightPixels;
w = displaymetrics.widthPixels;
}

By using this code we can get the screen size in pixels.