How can I increase the font size in Html.fromHtml?

141 views Asked by At

This code shows a View window, and displays a text document in HTML format.
I think the function is clear so:
All colors and formats work, but the font all comes in a default size and is rather small.
-I want to customize the font size.
-And I want to customize the background color of the page as well.

If there are other additions that can improve the presentation, I would be grateful to you

    Button btn_azkar = (Button)findViewById(R.id.btn_azkar);
    btn_azkar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            help();
        }
        @SuppressWarnings("deprecation")
        public void help() {
            try {
                InputStream inputStream = getAssets().open("azkar.txt");
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                BufferedReader BR = new BufferedReader(inputStreamReader);
                String line;
                StringBuilder msg = new StringBuilder();
                while ((line = BR.readLine()) != null) {
                    msg.append(line + "\n");
                }
                AlertDialog.Builder build = new AlertDialog.Builder(Info_Activity.this);
                build.setTitle(R.string.azkar);
            //  build.setIcon(R.drawable.icon);
                build.setMessage(Html.fromHtml(msg + ""));
                build.setNegativeButton(R.string.dilog_close, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        //Negative
                    }
                }).show();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
1

There are 1 answers

0
ghassan On

I found a temporary solution and it enlarges the font size of the layout completely:
So I fixed the font size of the buttons by dp and incremented: fontScale = 1.2f;. I got good results and am waiting for a better solution.

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(newBase);
        Configuration config = new Configuration(newBase.getResources().getConfiguration());
        config.fontScale = 1.2f;
        applyOverrideConfiguration(config);
    }