วิธีการปัดเศษ TextView ใน Android (Java) [ซ้ำ]

Aug 17 2020

ฉันมีรหัสต่อไปนี้ในกิจกรรมหลักของฉัน:

LinearesLayout = (LinearLayout) findViewById(R.id.linearlayout);
TextView textView = new TextView(this);
textView.setBackgroundResource(R.color.colorPrimary);
LinearesLayout.addView(textView);

ฉันจะกำหนดมุมของ TextView ให้กลมได้อย่างไร

คำตอบ

TalMantelmakher Aug 17 2020 at 22:40

สร้างไฟล์ XML ในโฟลเดอร์ res \ drawable - rounded_corners.xmlดังนี้:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="#ff0000"/>
  <corners android:radius="4dp" />
  <padding
    android:top="5dp"
    android:left="5dp"
    android:bottom="5dp"
    android:right="5dp" />
</shape> 

แทนที่บรรทัดนี้:

textView.setBackgroundResource(R.color.colorPrimary);

สำหรับสิ่งนี้:

textView.setBackgroundResource(R.drawable.rounded_corners);