กดปุ่มเพื่อสลับระหว่าง แสดง หรือ ซ่อน password
API 27
ภาพแรก First Name ได้รับ Focus ข้อความ Label จะลอยขึ้นไปเป็นสีชมพู
ส่วน Last Name ยังไม่ได้รับ Focus ข้อความ Label จะแสดงเป็น Hint ปกติ
ภาพที่สองเมื่อมีการใส่ข้อความลงไป ทั้ง First Name และ Last Name จะลอยขึ้นไป
Link
Drawable resources type
StateListDrawable
.GradientDrawable
.Shape Drawable
เป็นไฟล์ XML สำหรับวาดรูปทรงแบบต่างๆ ได้แก่ สี่เหลี่ยม วงกลม วงรี เส้นตรง รวมถึงองค์ประกอบต่างๆเช่น เส้นขอบ สี มุมโค้ง เป็นต้น
ใช้สร้าง GradientDrawable
State List
เป็นไฟล์ XML สำหรับกำหนดสถานะของการแสดงพื้นหลังของวิว เช่นปกติให้สีพื้นหลังแบบนึง เมื่อถูกคลิกก็เปลี่ยนไปเป็นอีกแบบนึง เป็นต้น มักใช้กับ Button
และ ListView
ใช้สร้าง StateListDrawable
Layer List
สำหรับจัดวาง Drawable หลายๆอัน แบบแยกเป็นชั้นๆ ทำให้เราเลือกวางแต่ละอันบนตำแหน่งที่ต้องการ โดยไม่ซ้อนทับกัน หรืออาจวางเยื้องกันได้
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context=".MainActivity"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="All Caps - Default Way" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="All Caps Off - XML Way" android:textAllCaps="false" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="All Caps On Programmatically" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="All Caps Off Programmatically" /> </LinearLayout> |
MainActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package com.phaisarn.ktapplication import android.support.v7.app.AppCompatActivity import android.os.Bundle import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) button3.setAllCaps(true) button4.setAllCaps(false) } } |