π€Android/Java
[Android] μλλ‘μ΄λ - TextView μμ±λ€(text, textColor, background, layout_margin, visibility, padding, gravity)
루리μΌγ
2023. 12. 21. 13:09
λ°μν
μλλ‘μ΄λμ TextViewλ νλ©΄μ ν μ€νΈλ₯Ό νμνλ λ° μ¬μ©λλ UI μμμ΄λ€. μ¬λ¬ κ°μ§ μμ±μ μ¬μ©νμ¬ ν μ€νΈ, μμ, λ°°κ²½, λ μ΄μμ λ±μ μ€μ ν μ μλ€.
μλλ‘μ΄λ TextView μμ±
- text: TextViewμ νμλλ ν μ€νΈ λ΄μ©μ μ€μ νλ€.
- textColor: ν μ€νΈμ μμμ μ§μ νλ€.
- background: TextViewμ λ°°κ²½μ μ€μ νλ€. λ°°κ²½μΌλ‘λ μμ, μ΄λ―Έμ§ λλ Drawable λ±μ μ¬μ©ν μ μλ€.
- layout_margin: TextViewμ μ¬λ°±μ μ€μ νλ€. layout_marginμ ν΅ν΄ μνμ’μ° μ¬λ°±μ μ€μ ν μ μλ€.
- visibility: TextViewμ νμ μ¬λΆλ₯Ό κ²°μ νλ€. visible, invisible, gone λ±μ κ°μΌλ‘ μ€μ ν μ μλ€.
- padding: TextView λ΄λΆμ ν μ€νΈμ ν λ리(κ²½κ³) μ¬μ΄μ μ¬λ°±μ μ§μ λ€.
- gravity: TextView λ΄μ ν μ€νΈλ₯Ό μ΄λμ μ λ ¬ν μ§λ₯Ό μ€μ νλ€. μλ₯Ό λ€μ΄, center, start, end λ±μΌλ‘ μ€μ ν μ μλ€.
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:text="μλ
νμΈμ."
android:textColor="#B85252"
android:background="#00ff00"
android:layout_margin="20dp"
android:visibility="invisible"
android:padding="20dp"
android:gravity="center"
</androidx.constraintlayout.widget.ConstraintLayout>
[μλλ‘μ΄λ μ€νλμ€ λμμΈ νλ©΄]
λ°μν