I'm trying to increase the font inside a fragment with the press of the button. But I'm facing problems with textView.getTextSize(), which return different values on different screen densities.
I tried the solution given here and here.
The solutions mentioned above suggest to use setTextSize(int unit, float size). Albeit, in my case, I'm trying to compare the values and have got no clue how can I compare the size of textView with dimensions that I'm using.
if (id == R.id.item1) {
if (textView.getTextSize() == requireContext().getResources().getDimension(R.dimen.text_medium)) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, requireContext().getResources().getDimension(R.dimen.text_large));
} else if (textView.getTextSize() == requireContext().getResources().getDimension(R.dimen.text_small)) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, requireContext().getResources().getDimension(R.dimen.text_medium));
} else {
// Toast.makeText(getActivity(), "size: "+, Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), "Cannot increase further!", Toast.LENGTH_SHORT).show();
}
}