Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java for Android项目中使文本的特定部分加粗?_Java_Android - Fatal编程技术网

如何在Java for Android项目中使文本的特定部分加粗?

如何在Java for Android项目中使文本的特定部分加粗?,java,android,Java,Android,如何使文本的某些部分加粗?在stringpars中,我希望文本的这一特定部分以粗体显示“股票市场是如何运作的?”并且文本的其余部分应保持正常 public class second extends AppCompatActivity { TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV

如何使文本的某些部分加粗?在stringpars中,我希望文本的这一特定部分以粗体显示“股票市场是如何运作的?”并且文本的其余部分应保持正常

public class second extends AppCompatActivity {
TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
textView = (TextView)findViewById(R.id.Text1);
    String pars = "How Stock Market works ?\n" +
            "They are called by the collective names of ‘buyers’ and 
‘sellers’.\n" +
            "\n" +
            "So imagine that there is a ‘tug of war’ situation between the 
‘buyers’ and the ‘sellers’. The one who wins this war will control the 
price.\n" +
            "\n" +
            "Case 1] Buyers control the game:\n" +
            "\n" +
            "For the buyers to control the game, there has to be more 
supply. More supply of shares would mean that sellers are desperate to sell 
 their part and hence this would give the control in the hands of buyers.\n" 
+

            "\n" +
            "This makes the market such an interesting place! After all 
predictability is boring and tedious. ";
    textView.setText(pars);
    textView.setMovementMethod(new ScrollingMovementMethod());
}
}

使用如下代码所示的可扩展字符串

  private String string="\"How Stock Market works ?\\n\" +\n" +
        "            \"They are called by the collective names of ‘buyers’ and \n" +
        "‘sellers’.\\n\" +\n" +
        "            \"\\n\" +\n" +
        "            \"So imagine that there is a ‘tug of war’ situation between the \n" +
        "‘buyers’ and the ‘sellers’. The one who wins this war will control the \n" +
        "price.\\n\" +\n" +
        "            \"\\n\" +\n" +
        "            \"Case 1] Buyers control the game:\\n\" +\n" +
        "            \"\\n\" +\n" +
        "            \"For the buyers to control the game, there has to be more \n" +
        "supply. More supply of shares would mean that sellers are desperate to sell \n" +
        " their part and hence this would give the control in the hands of buyers.\\n\" \n" +
        "+\n" +
        "\n" +
        "            \"\\n\" +\n" +
        "            \"This makes the market such an interesting place! After all \n" +
        "predictability is boring and tedious. ";
private SpannableString spannableString=new SpannableString(string);



  spannableString.setSpan(new StyleSpan(Typeface.BOLD), 0, 21, 0);
textView.setText(spannableString);