[Android Studio] การทำให้ Status Bar เป็น Transparent
Sep 1, 2018 · 1 min read

Status Bar คือ แถบที่แสดงสถานะต่างๆของเครื่อง เช่น แบตเตอรี่, เวลา, สัญญาณ wifi เป็นต้น
วิธีทำ
- ใน root ของ layout ให้ตั้งค่า android:fitsSystemWindows=“true”

2. ในเมธอด onCreate ให้ใส่คำสั่ง ดังนี้
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
หมายเหตุ : การตั้งค่าแบบนี้ทำให้หน้า layout ไม่มีการเว้น status bar ให้ ซึ่งเราต้องทำการ margin ด้านบนลงมาเอง