2013-02-25 58 views
0

如何在my xml的图形布局中以粗体显示我的文本?我希望我的标题以粗体显示,而结果则采用正常格式。谢谢。我希望你能帮助我处理这件事。以大胆显示文本

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/coordinates" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/instruction" /> 

    <TextView 
     android:id="@+id/result" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/result" /> 

    <Button 
     android:id="@+id/btn_process" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/btn_text" /> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="300dp" 
      android:orientation="vertical" > 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Original" /> 

      <ImageView 
       android:id="@+id/imageSource" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/test_ideal_graph" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Result" /> 

      <FrameLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

       <ImageView 
        android:id="@+id/imageAfter" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

       <ProgressBar 
        android:id="@+id/progressBar" 
        style="?android:attr/progressBarStyleLarge" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 
      </FrameLayout> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 
+0

在每个文本视图中添加android:textStyle =“bold” – 2013-02-25 07:56:48

+0

http://stackoverflow.com/a/5169604/1434631 – Nermeen 2013-02-25 07:57:51

回答

1

例如:

android:textStyle="bold" 

或斜体时被通缉:

android:textStyle="italic" 

欲了解更多信息:

http://developer.android.com/reference/android/text/style/package-summary.html

也对这个看线程的详细资料:

How do you change text to bold in Android?

+0

如果不是textView的所有内容都应该以粗体显示怎么办? – cookie23 2013-02-25 08:00:07

+0

使用,并在标签之间放置需要加粗的文本 – Max 2013-02-25 08:09:22

5

strings.xml

<string name="your_string_name"><b> I am bold text</b> And I am not bold</string> 

使用这种方法在格式化文本,以获得更多的灵活性。

还记得使用,Html.fromHtml("your html string");设置文本中的TextView

例如

String s="<b> I am text in bold </b> and I am not."; 
TextView t=new TextView(); 
t.setText(Html.fromHtml(s)); 
2

如果你想在TextView所有文本要大胆使用,

android:textStyle="bold"

如果你只想要一部分要大胆,你可以使用生成HTML中SpannableHtml.fromHtml()这样的:

String text = "This is some <b>sample</b> text"; yourTextView.setText(Html.fromHtml(text));

这里“样本”将以粗体显示。