Search code examples
androidandroid-studiolistviewandroid-intenttext-size

Can we change the Size of text which is written in values of putextra and assigned in next activity of textview?


I am working on a project in which, I am exporting string value from one activity to 2nd activity but I just can't resize that string value which is assigned inside TextView in second activity.

Code of 1st activity:

  if (modelList.get(position).getJtitle().equals("Hello World"))
            {
                Intent intent = new Intent(mContext,CodeActivity.class);
                intent.putExtra("actionBarTitle","Hello World");
                intent.putExtra("contentTv","Class HelloWorld\n" +
                        "{\n" +
                        "public static void main(String args[])\n" +
                        "{\n" +
                        "System.out.println(\"Welcome to Hello World Program\");\n" +
                        "}\n" +
                        "}");
                mContext.startActivity(intent);
            }

2nd activity code :

    setContentView(R.layout.activity_jcode);

    ActionBar actionBar = getSupportActionBar();

    TextView codetv = findViewById(R.id.jtextview);
    Intent intent = getIntent();
    String mActionBarTitle = intent.getStringExtra("actionBarTitle");
    String mContent = intent.getStringExtra("contentTv");
    actionBar.setTitle(mActionBarTitle);
    codetv.setText(mContent);
}

The output looks like this, how can we change that textSize: Output example


Solution

  • setContentView(R.layout.activity_jcode);
    
    ActionBar actionBar = getSupportActionBar();
    
    TextView codetv = findViewById(R.id.jtextview);
    Intent intent = getIntent();
    String mActionBarTitle = intent.getStringExtra("actionBarTitle");
    String mContent = intent.getStringExtra("contentTv");
    actionBar.setTitle(mActionBarTitle);
    codetv.setText(mContent);
    codetv.setTextSize(10); //Replace 10 with whatever size you want. 
    
    }