Jul 13, 2011

Add icon on the title bar

Add icon on the title bar

package com.AndroidFeatureIcon;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class AndroidFeatureIconActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

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


3 comments:

  1. Note:

    getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.icon);

    can be simplified to:

    setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.icon);

    in the same way that:

    getWindow().requestWindowFeature(Window.FEATURE_LEFT_ICON);

    can be simplified to:

    requestWindowFeature(Window.FEATURE_LEFT_ICON);

    ReplyDelete
    Replies
    1. but requestWindowFeature(Window.FEATURE_LEFT_ICON); show error and windows are force close

      Delete
  2. Oh, and you probably are aware of this, but JIC, there's also Window.FEATURE_RIGHT_ICON, which then allows an icon on the left, or the right *or* both sides of the title bar.

    Nice series of singular-subject, targeted posts by the way :)

    ReplyDelete

Infolinks In Text Ads