Android-TextView(文本顯示組件2)

來源:互聯網
上載者:User

標籤:

---恢複內容開始---

1.建立Android工程

2.TextView文字顏色設定

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:id="@+id/mytext1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ffff00"
    android:text="@string/hello"
    />
</LinearLayout>
運行效果如下

3.TextView文字大小設定

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:id="@+id/mytext1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#ffff00"
    android:textSize="22px"
    android:text="@string/hello"
    />
</LinearLayout>

運行效果如下

4.TextView上下距離設定

<TextView
    android:id="@+id/mytext2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="30px"
    android:text="網址:www.baidu.com"/>

運行效果如下

5.TextView距離上邊距離

<TextView
    android:id="@+id/mytext3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10px"

   android:maxLength="3">(最多顯示3個文字)
    android:text="ABABABABABABABA"/>

運行效果如下

6.TextView背景上的文字顯示

<TextView
    android:id="@+id/mytext4"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/log"(背景圖片)
    android:textStyle="bold"(文字加粗)
    android:text="這是背景圖片上的文字"/>

運行效果如下

7.TextView網址連結

 <TextView
    android:id="@+id/mytext5"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:textSize="36px"
    android:autoLink="all"
    android:text="網址:www.baidu.com"/>

運行效果如下

8.使用樣式表定義常用的組件屬性方便維護

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="style_msg">
       <item name="android:layout_width">fill_parent</item>
       <item name="android:layout_height">wrap_content</item>
       <item name="android:textColor">#000000</item>
       <item name="android:textSize">36px</item>
       <item name="android:autoLink">all</item>
    </style>
</resources>
注意:此檔案放在values目錄下

main.xml使用如下

<TextView
    android:id="@+id/mytext5"
    style="@style/style_msg"
    android:text="網址:www.baidu.com"/>

運行效果如下

 

Android-TextView(文本顯示組件2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.