TextView怎么在Android中使用

TextView怎么在Android中使用?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到佳縣網(wǎng)站設(shè)計(jì)與佳縣網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請(qǐng)、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋佳縣地區(qū)。

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è)置字號(hào)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" ···省略號(hào)居中顯示-->
  <!--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"/>
  <!--對(duì)郵件電話、添加鏈接-->
  <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="測(cè)試文字"
    android:textSize="25pt"
    android:shadowColor="#00f"
    android:shadowDx="10.0"
    android:shadowDy="8.0"
    android:shadowRadius="3.0"
    android:textColor="#f00"/>
  <!--測(cè)試密碼框-->
  <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"/>
  <!--測(cè)試密碼框-->
  <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"/>
  <!--通過(guò)Android:background指定背景-->
  <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="帶邊框的文本"
    android:textSize="25sp"
    android:background="@drawable/bg_border"/>
  <!--通過(guò)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">
  <!--制定圓角矩形的四個(gè)圓角半徑-->
  <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>

勾選效果通過(guò)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);
        }
      }
    });
  }
}

Android是什么

Android是一種基于Linux內(nèi)核的自由及開放源代碼的操作系統(tǒng),主要使用于移動(dòng)設(shè)備,如智能手機(jī)和平板電腦,由美國(guó)Google公司和開放手機(jī)聯(lián)盟領(lǐng)導(dǎo)及開發(fā)。

看完上述內(nèi)容,你們掌握TextView怎么在Android中使用的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前名稱:TextView怎么在Android中使用
網(wǎng)站路徑:http://bm7419.com/article36/pdhhpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、網(wǎng)站改版、小程序開發(fā)網(wǎng)頁(yè)設(shè)計(jì)公司、網(wǎng)站建設(shè)手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)