最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)中TextView各種常見使用方法小結(jié)

 更新時間:2019年04月09日 11:00:56   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)中TextView各種常見使用方法,結(jié)合實(shí)例形式總結(jié)分析了Android開發(fā)中TextView各種常見布局與功能實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)中TextView各種常見使用方法。分享給大家供大家參考,具體如下:

效果圖:

XML布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  android:id="@+id/root"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <!--設(shè)置字號20sp,文本框結(jié)尾處繪制圖片-->
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="我愛Java"
    android:textSize="20pt"
    android:drawableRight="@drawable/ic_dashboard_black_24dp" />
  <!--設(shè)置中間省略,所有字母大寫-->
  <!--android:ellipsize="middle" ···省略號居中顯示-->
  <!--android:textAllCaps="true"全體大寫-->
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:text="我愛Java我愛Java我愛Java我愛Java我愛Java我愛Java我愛Java我愛Java"
    android:ellipsize="middle"
    android:textAllCaps="true"/>
  <!--對郵件電話、添加鏈接-->
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:text="郵箱是 814484626@qq.com, 電話是 13100000000"
    android:autoLink="email|phone"/>
  <!--設(shè)置顏色、大小、并使用陰影-->
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="測試文字"
    android:textSize="25pt"
    android:shadowColor="#00f"
    android:shadowDx="10.0"
    android:shadowDy="8.0"
    android:shadowRadius="3.0"
    android:textColor="#f00"/>
  <!--測試密碼框-->
  <TextView
    android:id="@+id/password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/app_name"
    android:textSize="25sp"
    android:password="true"/>
  <!--測試密碼框-->
  <CheckedTextView
    android:id="@+id/check_text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="可勾選的文本"
    android:textSize="25sp"
    android:checkMark="@xml/check"/>
  <!--通過Android:background指定背景-->
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="帶邊框的文本"
    android:textSize="25sp"
    android:background="@drawable/bg_border"/>
  <!--通過Android:drawableLeft繪制一張圖片-->
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="圓角邊框,漸變背景的文本"
    android:textSize="25sp"
    android:background="@drawable/bg_border2"/>
</LinearLayout>

bg_bordor

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <!--設(shè)置背景色為透明色-->
  <solid android:color="#0000"/>
  <!--設(shè)置紅色邊框-->
  <stroke android:width="4px" android:color="#f00"/>
</shape>

bg_bordor2

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">
  <!--制定圓角矩形的四個圓角半徑-->
  <corners android:topLeftRadius="30px"
    android:topRightRadius="5px"
    android:bottomRightRadius="30px"
    android:bottomLeftRadius="5px"/>
  <!--指定邊框線條的寬度和顏色-->
  <stroke android:width="4px" android:color="#f0f"/>
  <!--指定使用漸變背景色,使用sweep類型漸變
  顏色從 紅色->綠色->藍(lán)色-->
  <gradient android:startColor="#f00"
    android:centerColor="#0f0"
    android:endColor="#00f"
    android:type="sweep"/>
</shape>

勾選效果通過xml selector實(shí)現(xiàn)切換

android:checkMark="@xml/check"/>

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/ok" android:state_selected="true"/>
  <item android:drawable="@drawable/no" android:state_selected="false"/>
</selector>

Java代碼添加點(diǎn)擊事件

public class Home extends AppCompatActivity {
  private int i = 0 ;
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);//顯示manLayout
    final CheckedTextView checkedTextView = (CheckedTextView) findViewById(R.id.check_text_view);
    checkedTextView.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if( i++ % 2 == 1 ){
          checkedTextView.setSelected(true);
        }
        else {
          checkedTextView.setSelected(false);
        }
      }
    });
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android編程之書架效果背景圖處理方法

    Android編程之書架效果背景圖處理方法

    這篇文章主要介紹了Android編程之書架效果背景圖處理方法,在前面一篇《android書架效果實(shí)現(xiàn)原理與代碼》的基礎(chǔ)上做了一定的修改,重寫GridView類處理了背景圖效果,需要的朋友可以參考下
    2015-12-12
  • Android自定義webView頭部進(jìn)度加載效果

    Android自定義webView頭部進(jìn)度加載效果

    這篇文章主要介紹了Android自定義webView頭部進(jìn)度加載效果,小編畫一條進(jìn)度線,然后加載webview上面,具體實(shí)現(xiàn)代碼大家參考下本文
    2017-11-11
  • Android列表動圖展示的實(shí)現(xiàn)策略

    Android列表動圖展示的實(shí)現(xiàn)策略

    這篇文章主要給大家介紹了關(guān)于Android列表動圖展示的實(shí)現(xiàn)策略的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11
  • android實(shí)現(xiàn)獲取有線和無線Ip地址的方法

    android實(shí)現(xiàn)獲取有線和無線Ip地址的方法

    這篇文章主要介紹了android實(shí)現(xiàn)獲取有線和無線Ip地址的方法,較為詳細(xì)的分析了Android獲取IP地址的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-08-08
  • Android Studio實(shí)現(xiàn)QQ的注冊登錄和好友列表跳轉(zhuǎn)

    Android Studio實(shí)現(xiàn)QQ的注冊登錄和好友列表跳轉(zhuǎn)

    最近做了一個項(xiàng)目,這篇文章主要介紹了Android Studio界面跳轉(zhuǎn),本次項(xiàng)目主要包含了注冊、登錄和好友列表三個界面以及之間相互跳轉(zhuǎn),感興趣的可以了解一下
    2021-05-05
  • Android編程實(shí)現(xiàn)Toast自定義布局簡單示例

    Android編程實(shí)現(xiàn)Toast自定義布局簡單示例

    這篇文章主要介紹了Android編程實(shí)現(xiàn)Toast自定義布局的方法,結(jié)合簡單實(shí)例形式分析了Toast自定義布局的實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-02-02
  • android電話模擬器(示例代碼)

    android電話模擬器(示例代碼)

    本篇文章我將為大家介紹一下android電話模擬器(示例代碼),需要的朋友可以過來參考下,希望對大家有所幫助
    2013-11-11
  • Android table布局開發(fā)實(shí)現(xiàn)簡單計(jì)算器

    Android table布局開發(fā)實(shí)現(xiàn)簡單計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了Android table布局開發(fā)實(shí)現(xiàn)簡單計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • 一文帶你深入理解Android Window系統(tǒng)

    一文帶你深入理解Android Window系統(tǒng)

    Android中的窗口系統(tǒng)是應(yīng)用程序用戶界面的核心組件之一,它負(fù)責(zé)管理可視化區(qū)域、處理用戶輸入事件以及與系統(tǒng)UI交互,本文將深入介紹與Android窗口系統(tǒng)相關(guān)的重要概念,需要的朋友可以參考下
    2023-10-10
  • [Alibaba-ARouter]淺談簡單好用的Android頁面路由框架

    [Alibaba-ARouter]淺談簡單好用的Android頁面路由框架

    這篇文章主要介紹了[Alibaba-ARouter]淺談簡單好用的Android頁面路由框架,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11

最新評論

徐水县| 洛阳市| 大姚县| 阜城县| 罗山县| 天峨县| 宜良县| 荥经县| 肥东县| 津市市| 聊城市| 阳高县| 赫章县| 富阳市| 手游| 股票| 邻水| 黄浦区| 两当县| 威信县| 枝江市| 交城县| 岳池县| 兴海县| 恩施市| 淳化县| 宁河县| 汪清县| 高州市| 房产| 井冈山市| 安多县| 专栏| 辽宁省| 南漳县| 汉源县| 昌宁县| 平罗县| 清涧县| 通海县| 全州县|