0

in the name of GOD

hello i have a text file and want to read and show into textview with different font and color for odd line and even line , how to change this reading code :

code :

File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"komeil.txt");

    StringBuilder text = new StringBuilder();

    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;


        text.append('\n');


        while ((line = br.readLine()) != null) {
            text.append(line);
            text.append('\n');

        }
    }
    catch (IOException e) {
        //You'll need to add proper error handling here
    }

like this text file :

file :

hello people i am student //black
i want to rad this file   //green
different color           //black
different font            //green
how to do this            //black
...                       //green
...                       //black
.                         //green
.                         //black
.                         //green
hkh114
  • 162
  • 1
  • 3
  • 15
  • See http://stackoverflow.com/questions/1529068/is-it-possible-to-have-multiple-styles-inside-a-textview – comodoro Jul 27 '12 at 17:06
  • You could use TextAppearanceSpans ... when adding the text into the text view, instead of inserting strings, you use Spans which are displayable styled Strings. http://developer.android.com/reference/android/text/style/TextAppearanceSpan.html – Nick Campion Jul 27 '12 at 17:07
  • i was Amateur programmer if you correct this code , i thankful !!! – hkh114 Jul 27 '12 at 18:46

1 Answers1

1

it is not possible in textview because textview accept only one color. for this, you have to use webview,create html page with lines with different colors

Android Dev
  • 198
  • 1
  • 3
  • 11