0Pricing
Jetpack Compose Academy · บทเรียน

พื้นหลัง เส้นขอบ และการตัด

เพิ่มสี เส้นกรอบ และรูปทรงมุมมน

พื้นหลัง เส้นขอบ และการตัด เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Decorate with Modifiers

Beyond sizing, modifiers can decorate a Composable. You can paint a background, draw a border, and round its corners. 🎨

Add a Background

background fills a Composable with a solid color. It paints the whole area the element occupies, including its size and fill.

Modifier.background(Color.Blue)

Use Theme Colors

Prefer theme colors over raw values. Pulling from MaterialTheme keeps your app consistent in light and dark mode.

Modifier.background(
  MaterialTheme.colorScheme.primary
)

Draw a Border

Use border to outline a Composable. Give it a thickness in dp and a color, and Compose draws the edge for you.

Modifier.border(2.dp, Color.Gray)

Meet Shapes

A Shape describes an outline like rounded or circular. Both background and border accept a shape to change their silhouette.

Rounded Corners

RoundedCornerShape softens corners by a radius in dp. It is the go-to shape for cards, buttons, and chips.

RoundedCornerShape(12.dp)

Shaped Background

Pass a shape to background and the color fills only inside that outline, giving you a tidy rounded panel.

Modifier.background(
  Color.LightGray,
  RoundedCornerShape(12.dp)
)

Clip the Content

clip trims anything drawn outside a shape. Use it so images and children respect your rounded corners.

Modifier.clip(RoundedCornerShape(12.dp))

Make a Circle

Reach for CircleShape when you want a perfect circle, like a round avatar or a floating button.

Modifier.clip(CircleShape)

Clip Before Drawing

Place clip before background so the fill is also rounded. Order in the chain decides what gets clipped.

Modifier
  .clip(RoundedCornerShape(12.dp))
  .background(Color.Cyan)

Combine for a Card

Stack clip, background, and border together to craft a polished card surface in just a few lines.

Modifier
  .clip(RoundedCornerShape(16.dp))
  .background(Color.White)
  .border(1.dp, Color.LightGray)

Quick Check

You want a rounded background where the fill itself is also rounded. Which modifier ensures that?

Recap

You can now style any element: background paints it, border outlines it, and clip with a Shape rounds it. 🎉

คำถามที่พบบ่อย

บทเรียน “พื้นหลัง เส้นขอบ และการตัด” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “พื้นหลัง เส้นขอบ และการตัด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “พื้นหลัง เส้นขอบ และการตัด”

เพิ่มสี เส้นกรอบ และรูปทรงมุมมน คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “พื้นหลัง เส้นขอบ และการตัด” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม

ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ระยะขอบ ขนาด และ fillMaxWidth
  2. พื้นหลัง เส้นขอบ และการตัด
  3. เหตุใดลำดับตัวปรับแต่งจึงสำคัญ
  4. weight และการกำหนดขนาดแบบยืดหยุ่น
← กลับไปที่ Jetpack Compose Academy