Wie runden Sie Ecken von TextView in Android (Java) ab? [Duplikat]
Aug 17 2020
Ich habe den folgenden Code in meiner Hauptaktivität:
LinearesLayout = (LinearLayout) findViewById(R.id.linearlayout);
TextView textView = new TextView(this);
textView.setBackgroundResource(R.color.colorPrimary);
LinearesLayout.addView(textView);
Wie kann ich die Ecken der Textansicht so einstellen, dass sie rund sind?
Antworten
TalMantelmakher Aug 17 2020 at 22:40
Erstellen Sie eine XML-Datei im Ordner res \ drawable - rounded_corners.xmlwie folgt :
<?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>
Ersetzen Sie diese Zeile:
textView.setBackgroundResource(R.color.colorPrimary);
dazu:
textView.setBackgroundResource(R.drawable.rounded_corners);