New to android

I have a radio group. When a radio button is clicked I want to change the value in my dimension file. Every view in my application has a text size value of @dimen/font. So when the user clicks on small, the value of font needs to be changed to 10 sp, for example. Any ideas on how to reference the dimension and change its value? TIA

    public void rbFontClicked(View view) {
        // Is the button now checked?
        boolean checked = ((RadioButton) view).isChecked();

        // Check which radio button was clicked
        switch(view.getId()) {
            case R.id.rbsmall:
                if (checked)
                    //set dimension to small font
                break;

            case R.id.rbmedium:
                if (checked)
                    // do nothing
                break;

            case R.id.rblarge:
                if (checked)
                    // set dimension to large font,
                break;
有帮助吗?

解决方案

Use this to read dimension value from the resources and change font size inside of a method of your Activity.

float size = getResources().getDimension(R.dimen.font);
((RadioButton) view).setTextSize(size);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top