如何在 Android 佈局 XML 檔案中定義下劃線文字?
此示例說明如何在 Android 佈局 xml 檔案中定義下劃線文字。
步驟 1 − 在 Android Studio 中建立新專案,轉至檔案 ⇒ 新專案,並填寫所有必需資訊以建立新專案。
步驟 2 − 將以下程式碼新增到 res/layout/activity_main.java
<? xml version= "1.0" encoding= "utf-8" ?> <RelativeLayout 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= ".MainActivity" > <TextView android :id= "@+id/textView" android :layout_width= "match_parent" android :layout_height= "wrap_content" android :layout_centerInParent= "true" android :gravity= "center" android :padding= "16dp" android :text= "Bottom of the screen" android :textAppearance= "@style/Base.TextAppearance.AppCompat.Large" /> </RelativeLayout>
步驟 3 − 將以下程式碼新增到 src/MainActivity.java
package app.tutorialspoint.com.sample ;
import android.os.Bundle ;
import android.support.v7.app.AppCompatActivity ;
import android.text.SpannableString ;
import android.text.style.UnderlineSpan ;
import android.widget.TextView ;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super .onCreate(savedInstanceState) ;
setContentView(R.layout. activity_main ) ;
TextView textView = findViewById(R.id. textView ) ;
SpannableString content = new SpannableString( "Content" ) ;
content.setSpan( new UnderlineSpan() , 0 , content.length() , 0 ) ;
textView.setText(content) ;
}
}步驟 4 − 將以下程式碼新增到 androidManifest.xml
<? xml version= "1.0" encoding= "utf-8" ?> <manifest xmlns: android = "http://schemas.android.com/apk/res/android" package= "app.tutorialspoint.com.sample" > <application android :allowBackup= "true" android :icon= "@mipmap/ic_launcher" android:label= "@string/app_name" android:roundIcon= "@mipmap/ic_launcher_round" android:supportsRtl= "true" android:theme= "@style/AppTheme" > <activity android:name= ".MainActivity" > <intent-filter> <action android:name= "android.intent.action.MAIN" /> <category android:name= "android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
讓我們嘗試執行你的應用程式。我假設你已將你的安卓移動裝置與電腦連線。要從 android studio 執行應用,請開啟你的一個專案活動檔案並單擊執行
工具欄中的圖示。選擇你的移動裝置,然後檢視你將顯示預設螢幕的移動裝置 -

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP