亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

本文實例講述了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">
  <!--設置字號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" />
  <!--設置中間省略,所有字母大寫-->
  <!--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"/>
  <!--設置顏色、大小、并使用陰影-->
  <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">
  <!--設置背景色為透明色-->
  <solid android:color="#0000"/>
  <!--設置紅色邊框-->
  <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類型漸變
  顏色從 紅色->綠色->藍色-->
  <gradient android:startColor="#f00"
    android:centerColor="#0f0"
    android:endColor="#00f"
    android:type="sweep"/>
</shape>

勾選效果通過xml selector實現(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代碼添加點擊事件

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);
        }
      }
    });
  }
}

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

希望本文所述對大家Android程序設計有所幫助。

相關文章

  • Android實現(xiàn)滑動效果

    Android實現(xiàn)滑動效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)滑動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Java語言讀取配置文件config.properties的方法講解

    Java語言讀取配置文件config.properties的方法講解

    今天小編就為大家分享一篇關于Java語言讀取配置文件config.properties的方法講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Android編程使用sax解析xml數(shù)據(jù)的方法詳解

    Android編程使用sax解析xml數(shù)據(jù)的方法詳解

    這篇文章主要介紹了Android編程使用sax解析xml數(shù)據(jù)的方法,結(jié)合實例形式詳細分析了Android使用sax解析xml數(shù)據(jù)的操作步驟及界面布局、單元測試等相關操作技巧,需要的朋友可以參考下
    2017-07-07
  • Android國際化之中英文語言切換

    Android國際化之中英文語言切換

    大家好,本篇文章主要講的是Android國際化之中英文語言切換,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • Android路由框架ARouter的使用示例

    Android路由框架ARouter的使用示例

    組件化或者模塊化開發(fā)模式,已逐漸成為熱浪的形式,使用這些模式可以讓我們程序更容易的擴展、更方便的維護、更快捷的同步開發(fā)與更簡單的單獨調(diào)試,而ARouter的出現(xiàn)就是讓組件間、模塊間是實現(xiàn)完全的獨立。ARouter主要解決組件間、模塊間的界面跳轉(zhuǎn)問題。
    2021-06-06
  • Android使用AlertDialog創(chuàng)建對話框

    Android使用AlertDialog創(chuàng)建對話框

    這篇文章主要為大家詳細介紹了Android使用AlertDialog創(chuàng)建對話框的方法料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android10 App 啟動分析進程創(chuàng)建源碼解析

    Android10 App 啟動分析進程創(chuàng)建源碼解析

    這篇文章主要為大家介紹了Android10 App啟動分析進程創(chuàng)建源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Android基于虹軟(ArcSoft)實現(xiàn)人臉識別

    Android基于虹軟(ArcSoft)實現(xiàn)人臉識別

    人工智能時代快速來臨,其中人臉識別是當前比較熱門的技術,在國內(nèi)也越來越多的運用,例如刷臉打卡,刷臉APP,身份識別,人臉門禁等。本文將為大家介紹Android基于虹軟(ArcSoft)實現(xiàn)人臉識別的demo,快來跟隨小編一起學習吧
    2021-12-12
  • 詳解kotlin中::雙冒號的使用

    詳解kotlin中::雙冒號的使用

    在?Kotlin?中?,?::?雙冒號操作符?的作用是獲取類,對象,函數(shù),屬性的?類型對象引用,這篇文章主要介紹了詳解kotlin中::雙冒號的使用,需要的朋友可以參考下
    2023-04-04
  • android計算器簡單實現(xiàn)代碼

    android計算器簡單實現(xiàn)代碼

    這篇文章主要為大家詳細介紹了android計算器的簡單實現(xiàn)代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03

最新評論