2011年7月23日星期六

在標題欄顯示圖標(icon) - Window.FEATURE_LEFT_ICON/Window.FEATURE_RIGHT_ICON

要在標題欄顯示圖標, 先要要求窗口功能 Window.FEATURE_LEFT_ICON 和/或 Window.FEATURE_RIGHT_ICON:
requestWindowFeature(Window.FEATURE_LEFT_ICON);
requestWindowFeature(Window.FEATURE_RIGHT_ICON);

再調用 setFeatureDrawableResource() 方法來設定它.

實例:

Window.FEATURE_LEFT_ICON/Window.FEATURE_RIGHT_ICON

package com.AndroidTitleIcon;

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

public class AndroidTitleIconActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
requestWindowFeature(Window.FEATURE_RIGHT_ICON);
setContentView(R.layout.main);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.icon);
getWindow().setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,R.drawable.icon);
}
}


1 則留言: