2012-01-26 7 views
0

가능한 중복 :
How do I programmatically set the background color gradient on a Custom Title Bar?안드로이드 그라데이션 응용 프로그램 제목 표시 줄

내가 응용 프로그램의 제목 표시 줄에 그라데이션 색상을 사용하고 싶습니다. 내가 어떻게 해?

미리 감사드립니다.

+1

하면이 http://stackoverflow.com/questions/6115715/how-do-i-programmatically-set-the-background-color-gradient-on-a-custom-title-ba – Ajay

답변

6

모든 사용자가 사용자 지정 제목을 사용하려고합니다.

맞춤 제목을 사용하지 않고이 작업을 수행했습니다. setContentView() 후에 활동의 onCreate() 코드 아래에서 사용하십시오.

GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] {Color.RED,Color.GREEN}); 
View title = getWindow().findViewById(android.R.id.title); 
View titleBar = (View) title.getParent(); 
titleBar.setBackgroundDrawable(gd); 

위의 코드로 즐기십시오. 아래 이미지는 제목 표시 줄 배경으로 그라디언트 색상이있는 앱의 스크린 샷입니다.

Gradient Color as Background of title bar

+0

시도 복잡한 사용자 정의 타이틀 대신에 매우 편리한 코드. + 1. –

+0

@AndroidKiller 감사합니다. –

관련 문제