我正在製作一個android應用程序,我想知道如何在android中使用下劃線實現彩色標題。下面的圖片是我想要的。添加帶有下劃線的彩色文本視圖
到目前爲止,我已經寫代碼:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".AddContact" >
<TextView
android:id="@+id/lbl_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/heading_name" />
<LinearLayout
android:layout_width="337dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6" >
<EditText
android:id="@+id/edit_first_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="5"
android:hint="@string/hint_firstname"
android:inputType="textCapSentences" />
<ImageButton
android:id="@+id/addimage"
android:layout_width="0dp"
android:layout_height="58dp"
android:layout_weight="1"
android:background="@drawable/ic_social_person" />
</LinearLayout>
<LinearLayout
android:layout_width="337dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<EditText
android:id="@+id/edit_last_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="4"
android:hint="@string/hint_lastname"
android:inputType="textCapSentences" />
</LinearLayout>
<TextView
android:id="@+id/lbl_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_number" />
<LinearLayout
android:layout_width="337dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<EditText
android:id="@+id/edit_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="2"
android:hint="@string/hint_number"
android:inputType="number" />
<Spinner
android:id="@+id/contact_number_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="@+id/lbl_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_email" />
<LinearLayout
android:layout_width="337dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<EditText
android:id="@+id/edit_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="2"
android:hint="@string/hint_email"
android:inputType="textEmailAddress" />
<Spinner
android:id="@+id/contact_email_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="@+id/lbl_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_address" />
<LinearLayout
android:layout_width="337dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<EditText
android:id="@+id/edit_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="2"
android:hint="@string/hint_address"
android:inputType="textPostalAddress" />
<Spinner
android:id="@+id/contact_address_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="@+id/lbl_event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_event" />
<LinearLayout
android:layout_width="337dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<EditText
android:id="@+id/edit_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="2"
android:hint="@string/hint_date"
android:inputType="date" />
<Spinner
android:id="@+id/contact_date_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
任何幫助,將不勝感激
請參考以下鏈接http://stackoverflow.com/questions/3282940/set-color-of-textview-span-in-android/3282962#3282962 – SathishKumar