2012-07-03 3 views
12

는 내가 텍스트 뷰를 가지고 나는 그러나, 나는 XML을 통해이 작업을 수행하는 방법을 알아낼 수 없습니다XML을 통해 텍스트 뷰의 배경색을 홀로그램으로 설정하는 방법은 무엇입니까?

here.을 언급 한 바와 같이 홀로그램 녹색 빛으로 배경색을 설정 할 것입니다. 가능한가? 현재 가지고있는 항목 :

<TextView 
     android:text="2" 
     android:textSize="200sp" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/textView2" 
     android:background="#00FF00" 
     android:gravity="center" 
     android:textColor="#EEEEEE" 
     android:layout_alignParentRight="true" /> 

그러나 배경을 어떻게 든 변경하려면 홀로 녹색 표시등을 변경할 수 없습니다.

누구에게 의견이 있습니까? 나는 "@android : color /"를 시도했지만 주사위는 사용하지 않았다.

+0

텍스트 뷰의 배경색은 전체 화면 표시하고이 주제에 대한 API 페이지입니다 당신은 저를 알려주세요 .Could 텍스트 뷰의 한 줄만 배경색을 설정하는 방법. 예를 들어 (오늘)은 텍스트 뷰입니다. 텍스트 뷰 (TOday)에 대해서만 녹색 배경을 원합니다. – user2841300

답변

29

통해 자바 : XML을 통해

TextView test = (TextView) view.findViewById(R.id.textView2); 
test.setBackgroundResource(context.getResources().getColor(android.R.color.holo_green_light)); 

는 :

<TextView 
     android:text="2" 
     android:textSize="200sp" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/textView2" 
     android:style="@style/textviewStyle" 
     android:background="@android:color/holo_green_light" 
     android:gravity="center" 
     android:textColor="#EEEEEE" 
     android:layout_alignParentRight="true" /> 

This

2

android:background="@android:color/holo_green_light" 나를 위해 작동하는 것 같습니다. 대상 API 버전에 Holo 테마가 포함되어 있습니까?

관련 문제