[Android Studio] การทำให้ Status Bar เป็น Transparent

Huzen Karode
Sep 1, 2018 · 1 min read
Status Bar แบบ Transparent

Status Bar คือ แถบที่แสดงสถานะต่างๆของเครื่อง เช่น แบตเตอรี่, เวลา, สัญญาณ wifi เป็นต้น

วิธีทำ

  1. ใน 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 ด้านบนลงมาเอง

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade