private Button buttonZoomOut;
private Button buttonZoomIn;
private float textSize = 18f; // 初始字体大小
private final float minTextSize = 12f; // 字体大小最小限制
private final float maxTextSize = 32f; // 字体大小最大限制
private final float stepSize = 2f; // 字体变化步长
buttonZoomOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textSize -= stepSize;
if (textSize < minTextSize) {
textSize = minTextSize;
}
textView.setTextSize(textSize);
textView2.setTextSize(textSize);
textView3.setTextSize(textSize);
textView4.setTextSize(textSize);
textView1.setTextSize(textSize);
}
});
buttonZoomIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textSize += stepSize;
if (textSize > maxTextSize) {
textSize = maxTextSize;
}
textView.setTextSize(textSize);
textView2.setTextSize(textSize);
textView3.setTextSize(textSize);
textView4.setTextSize(textSize);
textView1.setTextSize(textSize);
}
});
09-30
6963
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)