Custom Notification을 만들다 보니 단말마다 Notification의 배경과 폰트색상이 달라서 고민이 되더군요.

그냥 시스템 색상 무시하고 배경과 폰트색을 임의로 칠해보았더니만 아무래도 좀 어색합니다.


인터넷 뒤지다 재미있는 방법으로 해결한 분이 있어서 공유해봅니다.

개념만 이해하면 유사한 문제들을 비슷하게 풀 수 있을 것 같네요.

(재미있는 방법은 3번에서 나옵니다.)


1) 백그라운드색 맞추기

  이건 기본적으로 됩니다만, 4.0 이상 단말에서 이상하게 나오는 경우, targetSDKVersion을 14 이상으로 줍니다.

  이건 그냥 Android 버그라고 봐야 할지......

  관련링크 : http://stackoverflow.com/questions/8659909/default-notification-background-color


2) 폰트색상 맞추기(2.3 이상)

  2.3 이상 단말 대상으로만 서비스한다면 간단합니다.

  TextView에 다음만 추가해주면 됩니다. 

   style = "@android:style/TextAppearance.StatusBar.EventContent" 

   관련링크 : http://stackoverflow.com/questions/6250356/how-to-use-default-notification-style


3) 폰트색상 맞추기(전체)

  하지만 아직까지는 2.2 이하 단말들을 무시하기란 쉽지 않죠.

  또다른 방법은 프로그램적으로 시스템 폰트 색을 가져오는 방법입니다.

  원리는 간단히 임의로 Notification을 만든 다음 시스템에 의해 생성된 TextView로부터 폰트 색을 가져온다는 것입니다.^^

  관련 링크 : http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/7320604#7320604


  아래는 폰트색상만 가져오는 함수로 바로 쓸 수 있게 만들어 놓은 소스입니다.


 	public static int getDefaultNotificationTextColor(Context context){
		int textColor;
		try{
			Notification ntf = new Notification();
			ntf.setLatestEventInfo(context, T, null, null);
			LinearLayout group = new LinearLayout(context);
			ViewGroup event = (ViewGroup) ntf.contentView.apply(context, group);
			textColor = recurseGroup(event);
			group.removeAllViews();
		} catch (Exception e){
			textColor = android.R.color.white;
		}
		return textColor;
	}

	public static int recurseGroup(ViewGroup gp){
		final int count = gp.getChildCount();
		for (int i = 0; i < count; ++i){
			if (gp.getChildAt(i) instanceof TextView){
				final TextView text = (TextView) gp.getChildAt(i);
				final String szText = text.getText().toString();
				if (T.equals(szText))
					return text.getTextColors().getDefaultColor();
			} else if (gp.getChildAt(i) instanceof ViewGroup)
				return recurseGroup((ViewGroup) gp.getChildAt(i));
		}
		return -1;
	}