Kt: Label ใน EditText ใช้ TextInputLayout

API 27

ภาพแรก First Name ได้รับ Focus ข้อความ Label จะลอยขึ้นไปเป็นสีชมพู
ส่วน Last Name ยังไม่ได้รับ Focus ข้อความ Label จะแสดงเป็น Hint ปกติ

ภาพที่สองเมื่อมีการใส่ข้อความลงไป ทั้ง First Name และ Last Name จะลอยขึ้นไป

Continue reading

Drawable resources

Link

Drawable resources type

  1. Bitmap File A bitmap graphic file (.png, .jpg, or .gif). Creates a BitmapDrawable.
  2. Nine-Patch File A PNG file with stretchable regions to allow image resizing based on content (.9.png). Creates a NinePatchDrawable.
  3. Layer List A Drawable that manages an array of other Drawables. These are drawn in array order, so the element with the largest index is be drawn on top. Creates a LayerDrawable.
  4. State List An XML file that references different bitmap graphics for different states (for example, to use a different image when a button is pressed). Creates a StateListDrawable.
  5. Level List An XML file that defines a drawable that manages a number of alternate Drawables, each assigned a maximum numerical value. Creates a LevelListDrawable.
  6. Transition Drawable An XML file that defines a drawable that can cross-fade between two drawable resources. Creates a TransitionDrawable.
  7. Inset Drawable An XML file that defines a drawable that insets another drawable by a specified distance. This is useful when a View needs a background drawable that is smaller than the View’s actual bounds.
  8. Clip Drawable An XML file that defines a drawable that clips another Drawable based on this Drawable’s current level value. Creates a ClipDrawable.
  9. Scale Drawable An XML file that defines a drawable that changes the size of another Drawable based on its current level value. Creates a ScaleDrawable
  10. Shape Drawable An XML file that defines a geometric shape, including colors and gradients. Creates a GradientDrawable.

Shape Drawable
เป็นไฟล์ XML สำหรับวาดรูปทรงแบบต่างๆ ได้แก่ สี่เหลี่ยม วงกลม วงรี เส้นตรง รวมถึงองค์ประกอบต่างๆเช่น เส้นขอบ สี มุมโค้ง เป็นต้น
ใช้สร้าง GradientDrawable

State List
เป็นไฟล์ XML สำหรับกำหนดสถานะของการแสดงพื้นหลังของวิว เช่นปกติให้สีพื้นหลังแบบนึง เมื่อถูกคลิกก็เปลี่ยนไปเป็นอีกแบบนึง เป็นต้น มักใช้กับ Button และ ListView
ใช้สร้าง StateListDrawable

Layer List
สำหรับจัดวาง Drawable หลายๆอัน แบบแยกเป็นชั้นๆ ทำให้เราเลือกวางแต่ละอันบนตำแหน่งที่ต้องการ โดยไม่ซ้อนทับกัน หรืออาจวางเยื้องกันได้

KT: กำหนด All Caps ให้ Button

activity_main.xml

MainActivity.kt