0

I want to adjust app font size to device size. I have values, values-hdpi, values-ldpi.. folders and added there dimens.xml file and set dimens like this <dimen name="task_check_box_font">16sp</dimen>. But then I get

font size to large to fit in cache error.

How to solve it? Thanks

BenasG
  • 23
  • 4

1 Answers1

0

Try this!

Create ScreenWidth.java

public class ScreenWidth {

    public ScreenWidth(){}

    @SuppressLint("NewApi")
    public int getScreenWidth(Context context) {
        int columnWidth ;
        WindowManager wm = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        final Point point = new Point();
        try {
            display.getSize(point);
        } catch (java.lang.NoSuchMethodError ignore) { // Older device
            point.x = display.getWidth();
            point.y = display.getHeight();
        }   

        columnWidth = point.x;


        return columnWidth;
    }

}

now create object of above class to get screen size pragmatically.

ScreenWidth SW = new ScreenWidth();
int width_sc =SW.getScreenWidth(this);
TextView t1 = (TextView)findViewById(R.id.t1);
t1.setTextSize(((width_sc*22)/768));

Hope this may help you!

Krupa Patel
  • 3,309
  • 3
  • 23
  • 28