【问题标题】:Bold text in Android Studio.. just one word? javaAndroid Studio 中的粗体字……只有一个字?爪哇
【发布时间】:2015-03-04 15:17:39
【问题描述】:

我有一个微调器,我需要在其中用粗体写一个单词以使其更具可读性。有人知道如何做到这一点吗?我尝试过但失败了,因为我似乎只能使整个事情变得粗体。我想让这个词使用粗体。

这是我的代码:

public class Interactions extends Activity implements OnItemSelectedListener {


Spinner spinner;
TextView showmed;
private String[] state = {"Adalimumab",
        "Etanercept",
        "Tacrolimus",
        "Mycophenolic Acid",
        "Bicalutamide",
        "Darbepoetin alfa",
        "Ciclosporin",
        "Interferon beta-1a",
        "Triptorelin",
        "Pegfilgrastim"
};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    if (MinderActivity.alarms) {
        setTheme(R.style.MyTheme);
    } else {
        setTheme(R.style.MyTheme);
    }
    setContentView(R.layout.activity_interactions);
    System.out.println(state.length);
    showmed = (TextView) findViewById(R.id.showmed);
    spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, state);
    adapter_state
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter_state);
    spinner.setOnItemSelectedListener(this);

}

public void onItemSelected(AdapterView<?> parent, View view, int position,
                           long id) {

    switch(position)
    {

        case 0:
            showmed.setText("Adalimumab\n" +
                            "Uses:\n" + "Treating a variety of moderate to severe inflammatory conditions (eg, rheumatoid arthritis, juvenile idiopathic arthritis [JIA], psoriatic arthritis, ankylosing spondylitis). It is also used to treat certain patients with moderate to severe Crohn disease, ulcerative colitis, or chronic plaque psoriasis. It may be used alone or in combination with other medicine. It may also be used for other conditions as determined by your doctor.\n" +
                            "\n" + "Alternative Names\n"+ "Humira\n"+ "Risks:\n"+ "Patients who use adalimumab have an increased risk of developing serious and sometimes fatal infections (eg, bacterial, viral, or fungal infections; tuberculosis [TB]). Most patients who developed these infections were also taking medicine that suppressed their immune system (eg, corticosteroids, methotrexate).\"TB may be caused by a new infection or by reactivation of a previous infection. Patients should receive a TB skin test before using adalimumab. Patients who test positive for TB should begin treatment for TB before starting adalimumab. All patients should also be monitored for signs of TB while using adalimumab, even if their TB test is negative.\n" +
                            "\n" + "Interactions\n"+ "\n"


            );
            break;

【问题讨论】:

    标签: java android text android-studio spinner


    【解决方案1】:

    使用SpannableStringBuilder 将new StyleSpan(Typeface.BOLD) 应用于您想要的文本部分。

    或者,将该部分包装在&lt;b&gt; 标记中并使用Html.fromHtml(),让它使用粗体格式为您构建Spanned。

    【讨论】:

      猜你喜欢
      • 2011-10-02
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 2011-06-24
      相关资源
      最近更新 更多