Increasing and Decreasing the font sizes of the an

2019-08-10 15:14发布

Actually i want to specify the custom text size in my application by user selection. Below is a figure that demonstrate the idea/theme

enter image description here

So, for that i have an idea to achieve this.

I will create a dialog in the view which having the user input options to increase/ decrease the font size. after changing the font size, i vll apply the same to the application. (+) & (-) signs will work to change the font size as well as seek bar too.

Here my question is is there any specific font style/ size changes in build android class / library / any other idea is available?

any help will be appreciate. mean while i will come with something which i try. Thankyou

5条回答
虎瘦雄心在
2楼-- · 2019-08-10 15:25

You can do this simply by:

    //Adjust values with whatever your need is
    int SIZE_LARGE = 24; 
    int SIZE_SMALL= 16;

    btnLargeText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, LARGE_SIZE);
        }
    });

    btnSmallText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, SIZE_SMALL);
        }
    });
查看更多
三岁会撩人
3楼-- · 2019-08-10 15:32

you can check

btnTextDeSave.setOnClickListener(onClickEven);
        btnTextInSave.setOnClickListener(onClickEven);

public OnClickListener onClickEven = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
                break;
            case R.id.btTextDeSave:
                txtDescriptionSave.setTextSize(TypedValue.COMPLEX_UNIT_PX, (txtDescriptionSave.getTextSize() - 2f));
                break;
            case R.id.btTextInSave:
                txtDescriptionSave.setTextSize(TypedValue.COMPLEX_UNIT_PX, (txtDescriptionSave.getTextSize() + 2f));
                break;

            default:
                break;
            }

        }
    };
查看更多
戒情不戒烟
4楼-- · 2019-08-10 15:34

To increase the size of your textView you can use

_percentField.setTextSize(values[0]*2);

where values is an array.

And to decrease you can try

 _percentField.setTextSize(values[0]/2);
查看更多
我命由我不由天
5楼-- · 2019-08-10 15:37

You can try this-

    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, <font-size value in integer> );

    // to update your changes
    textView.invalidate();
查看更多
ら.Afraid
6楼-- · 2019-08-10 15:51

do it this way

float fs = prefs.getFloat("fontsize", 12);
seekbar.setProgress((int)fs);
layout.setTextSize(TypedValue.COMPLEX_UNIT_PX,seekbar.getProgress());

and don't forget onProgressChanged:

layout.setTextSize(TypedValue.COMPLEX_UNIT_PX,progress);
查看更多
登录 后发表回答