TextView의 텍스트 기본 색상은 무엇입니까?
색상을 빨간색으로 설정 한 후 색상을 다시 기본값으로 설정하고 싶지만 기본 색상이 무엇인지 모르겠습니다. 아는 사람이 있습니까?
이전 색상을 저장 한 다음이를 사용하여 원래 값을 복원 할 수 있습니다. 다음은 그 예입니다.
ColorStateList oldColors = textView.getTextColors(); //save original colors
textView.setTextColor(Color.RED);
....
textView.setTextColor(oldColors);//restore original colors
그러나 일반적으로 기본 TextView
텍스트 색상은에 적용된 현재 테마에서 결정됩니다 Activity
.
실제로 색상 TextView는 다음과 같습니다.
android:textColor="@android:color/tab_indicator_text"
또는
#808080
에 정의 된 몇 가지 기본 색상이 있습니다. android.R.color
int c = getResources().getColor(android.R.color.primary_text_dark);
속성에서 다음 값을 가져옵니다.
int[] attrs = new int[] { android.R.attr.textColorSecondary };
TypedArray a = getTheme().obtainStyledAttributes(R.style.AppTheme, attrs);
DEFAULT_TEXT_COLOR = a.getColor(0, Color.RED);
a.recycle();
텍스트 색상을 지정하지 않은 경우 Android가 사용하는 테마에는 기본값이 있습니다. 다양한 Android UI (예 : HTC Sense, Samsung TouchWiz 등)에서 색상이 다를 수 있습니다. Android에는 _dark
및 _light
테마가 있으므로 기본값이 다릅니다 (바닐라 Android에서는 둘 다 거의 검은 색). 그러나 장치 전체에 일관된 스타일을 제공하기 위해 기본 텍스트 색상을 직접 정의하는 것이 좋습니다.
코드에서 :
getResources().getColor(android.R.color.primary_text_dark);
getResources().getColor(android.R.color.primary_text_light);
XML에서 :
android:color="@android:color/primary_text_dark"
android:color="@android:color/primary_text_light"
바닐라 안드로이드 참고로 어두운 테마 텍스트 색상입니다 #060001
과 빛 테마 그건 #060003
API v1을하기 때문이다. 여기에서 안드로이드 스타일 클래스보기
나는 그것이 오래되었다는 것을 알고 있지만 기본 밝은 테마가있는 내 테마 편집기에 따르면 기본
textPrimaryColor = #000000
과
textColorPrimaryDark = #757575
기본 색상이 없습니다. 그것은 모든 장치가 자신을 가질 수 있음을 의미합니다.
기본 색상 정수 값은 16711935 (0x00FF00FF)라고 생각합니다.
야 이거 먹어봐
ColorStateList colorStateList = textView.getTextColors();
String hexColor = String.format("#%06X", (0xFFFFFF & colorStateList.getDefaultColor()));
나는 android:textColor="@android:color/secondary_text_dark"
기본 TextView 색상에 더 가까운 결과를 제공 한다는 것을 발견했습니다 android:textColor="@android:color/tab_indicator_text"
. 사용중인 테마에 따라 secondary_text_dark / light간에 전환해야한다고 가정합니다.
참고 URL : https://stackoverflow.com/questions/6468602/what-is-default-color-for-text-in-textview
'Program Tip' 카테고리의 다른 글
URL이 존재하지 않는 경우 file_get_contents (0) | 2020.11.09 |
---|---|
Github : gh- 페이지를 마스터로 미러링 (0) | 2020.11.09 |
레이아웃이없는 Razor보기 (0) | 2020.11.09 |
특정 필드 값을 기준으로 먼저 정렬 (0) | 2020.11.09 |
SQL Server® 2016 Express 전체 다운로드 (0) | 2020.11.09 |