2

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>
4

3 に答える 3

4

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));
于 2013-02-25T07:59:13.563 に答える
2

例えば:

android:textStyle="bold"

または斜体が必要な場合:

android:textStyle="italic"

詳細については:

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

詳細については、このスレッドも参照してください。

Androidでテキストを太字に変更するにはどうすればよいですか?

于 2013-02-25T07:57:55.733 に答える
2

TextView内のすべてのテキストを太字にしたい場合は、

android:textStyle="bold"

その一部だけを太字にしたい場合は、次のようにSpannable使用して Html から生成できます。Html.fromHtml()

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

ここで「サンプル」は太字になります。

于 2013-02-25T10:41:58.360 に答える