bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

TextView怎么在Android中使用

TextView怎么在Android中使用?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

站在用戶的角度思考問題,與客戶深入溝通,找到佳縣網站設計與佳縣網站推廣的解決方案,憑借多年的經驗,讓設計與互聯網技術結合,創造個性化、用戶體驗好的作品,建站類型包括:網站設計、成都網站制作、企業官網、英文網站、手機端網站、網站推廣、域名申請、網絡空間、企業郵箱。業務覆蓋佳縣地區。

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,文本框結尾處繪制圖片-->
  <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實現切換

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是什么

Android是一種基于Linux內核的自由及開放源代碼的操作系統,主要使用于移動設備,如智能手機和平板電腦,由美國Google公司和開放手機聯盟領導及開發。

看完上述內容,你們掌握TextView怎么在Android中使用的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注創新互聯行業資訊頻道,感謝各位的閱讀!

當前名稱:TextView怎么在Android中使用
網站路徑:http://vcdvsql.cn/article36/pdhhpg.html

成都網站建設公司_創新互聯,為您提供網站維護網站改版小程序開發網頁設計公司網站建設手機網站建設

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網站建設