I am trying to implement a button that will increase the font size of text in TextView
I have came up with the following :
Button biggerFont;
TextView centerTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
biggerFont = (Button) findViewById(R.id.btn_bigger_font);
centerTextView = (TextView) findViewById(R.id.textView_center);
biggerFont.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
float tempSize = centerTextView.getTextSize();
Log.d(USER_SERVICE, Float.toString(tempSize));
centerTextView.setTextSize(++tempSize);
}
});
// ...
}
But this will increase the font size a lot! each time I click the button. On logging I have check and tempSize
increases not by 1 but irregularly (44->90->182).
I have also tried using
float tempSize = centerTextView.getTextSize() + 1;
but the same thing.