커스텀 타이틀바 만드는 방법

출처 : http://www.helloandroid.com/tutorials/how-create-custom-titlebar

boolean customTitleSupported;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//check if custom title is supported BEFORE setting the content view!
customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

//set contentview
setContentView(R.layout.mainscreen);

//set custom titlebar
customTitleBar(getText(R.string.app_name).toString(), getText(
R.string.title_main_menu).toString());
}

public void customTitleBar(String left, String right) {
if (right.length() > 20) right = right.substring(0, 20);
// set up custom title
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.customtitlebar);
TextView titleTvLeft = (TextView) findViewById R.id.titleTvLeft);
TextView titleTvRight = (TextView) findViewById(R.id.titleTvRight);

titleTvLeft.setText(left);
titleTvRight.setText(right);

ProgressBar titleProgressBar;
titleProgressBar = (ProgressBar) findViewById(R.id.leadProgressBar);

//hide the progress bar if it is not needed
titleProgressBar.setVisibility(ProgressBar.GONE);
}
}

Related Posts

답글 남기기

이메일 주소는 공개되지 않습니다.