I'm working on rendering a text on textview. I'm trying to add two buttons to zoom in and out the text inside text view and the code goes like this
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chapter_view);
String chapter;
chapter=getIntent().getExtras().getString("ChapterName");
final StringBuffer buffer = new StringBuffer();
int id= getResources().getIdentifier(chapter,"raw",getPackageName());
try{
DataInputStream dataIO= new DataInputStream(getResources().openRawResource(id));
String strLine= null;
while((strLine = dataIO.readLine())!=null){
buffer.append(strLine);
buffer.append("\n");
}
dataIO.close();
}catch(Exception e){
}
final TextView tv=(TextView) findViewById(R.id.chapter);
tv.setText(buffer.toString());
Button zoomIn = (Button) findViewById(R.id.zoomin);
zoomIn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
textSize = tv.getTextSize();
tv.setTextSize((float) (textSize+0.25));
}
});
Button zoomOut = (Button) findViewById(R.id.zoomout);
zoomOut.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
textSize = tv.getTextSize();
tv.setTextSize((float) (textSize-0.25));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.chapter_view, menu);
return true;
}
}
But the problem I'm getting is the even upon clicking zoom out button, it still increasing the font size of the text. Please help me out in this. Also once I close one chapter and opens another, the text size will reset to its default value. Are there any solutions regarding this. I'm thinking of using the namevalue pair for this solution.