2011-11-25 6 views
-1
<string name="no_city"><font color='#FF0000'><b>Please select your location under Preferences in the menu</b></font> </string> 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.contents); 
    this.setContentView(R.layout.contents); 

    ChangeLog cl = new ChangeLog(this); 
    if (cl.firstRun()) 
     cl.getFullLogDialog().show(); 


    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 

    TextView text1 = (TextView)findViewById(R.id.textview1); 

    Resources res = getResources(); 
    String text = String.format(res.getString(R.string.no_city)); 
    CharSequence styledText = Html.fromHtml(text); 

    text1.setText(prefs.getString("listPref",res.getString(R.string.no_city))); 

은 내가 no_city 문자열의 텍스트의 색상을 변경하려합니다. 나는 위로 문자열을 입력하고 자바는 밑에 입력하는 방법을 가지고있다. Ihav는 16 진수와 색상 이름을 모두 물었고 어느 ​​것도 작동하지 않았습니다. 변경 사항을 참조하는 방법에 대한 Google 개발자 사이트에서이 정보를 찾았지만 잘 컴파일되지만 텍스트는 여전히 흰색입니다. 목록에서 아무 것도 선택하지 않으면 기본적으로 표시되는 것과 같이 목록 기본 설정과 함께 문자열을 사용하고 있습니다. 사용자가 선택을하면 텍스트가 흰색이어야하므로 xml 또는 java 파일에서 전체 텍스트보기 색상을 변경할 수 없습니다. 나는 작게 뭔가를 놓치고있는 벌이거나 뭔가를 간과하고있다. 그러나 나는 그것을 추적 할 수 없다.변경하기 문자열 텍스트 색상

답변

0

는 BufferType로 SPANNABLE 지정
0

시도해 보셨습니까 text1.setTextColor() ???

text1.setText(styledText, TextView.BufferType.SPANNABLE); 
0

직접 사용할 수 있습니다 :

txt.setText(Html.fromHtml(getResources().getString(R.string.no_city)); 

this

를 참조하면 뷰의 텍스트를 설정할 때