2017-04-08 3 views
0

텍스트 파일을 사용하여 텍스트를 가져 오는 앱이 있습니다. 텍스트를 가져 와서 Textview에 파일을 읽어 텍스트 뷰에 추가하면 제대로 작동하지만 텍스트에 형식을 추가하고 싶습니다. 머리말을 그렇게 대담하게 만드는 것.텍스트 파일의 텍스트를 Android의 텍스트 뷰로 포맷하는 방법

private void openFile() 
{ 
    String tema = "Message"; 
    TextView temas = (TextView) findViewById(R.id.tutorial); 
    temas.setText(title); 
    temas.setTextSize(25); 

    temas.setTextColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); 
    try { 
     InputStream is = getAssets().open("tutorials/tutorial1.txt"); 
     int size = is.available(); 

     byte[] buffer = new byte[size]; 
     is.read(buffer); 
     is.close(); 

     String text = new String(buffer); 


     TextView tv = (TextView) findViewById(R.id.text); 
     tv.setText(text); 
     tv.setTextSize(20); 
     tv.setTextColor(Color.parseColor("#000000")); 
    } catch (IOException e) { 
     throw new RuntimeException(e); 
    } 

} 

답변

0
HTML 태그를 사용할 수 있습니다

당신이 다음을 수행 할 수 있습니다 포맷 할 단어를 알고 있다면이 답변 here

을 참조 추가 정보를 원하시면 예를

String x ="Hello <b>World!</b>"; 
rextView.setText(x); 

text.For 형식의 표시하는 방법 해당 단어/문자가 태그를 추가하고 문자열에 다시 추가 할 때까지 문자열을 반복합니다. 또 다른 방법은 그 단어 앞에 특수 문자를 추가하는 것입니다. 예를 들어 제목을 굵게 만들고 싶으면 단어 앞에 '#'와 같은 문자를 추가 할 수 있습니다. 그래서 내가 아는 파일을 읽을 때 어떤 서식을 나는 어떤 단어에 적용해야합니다.

+0

예,하지만 텍스트 파일에는 작동하지 않습니다. –