Change font for EditText in Android?

2019-01-18 18:06发布

Is there any way to change the font for a EditText in Android? I want it to match the font's I set for all my textViews.

7条回答
SAY GOODBYE
2楼-- · 2019-01-18 18:55

You can create font folder under res directory in last version Android studio 3 .Then copy and past it you'r font to font folder. Now just add fontFamily to EditText tag xml.

like below.

        <EditText
            android:id="@+id/subject"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/headerShare"
            android:layout_marginBottom="5dp"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:background="@drawable/edittext_bg"
            android:fontFamily="@font/ritaric"
            android:gravity="start"
            android:hint="Subject"
            android:inputType="text"
            android:maxHeight="50dp"
            android:padding="16dp"
            android:textColor="@color/black"
            android:textColorHint="@color/black"
            android:textSize="@dimen/colors_textview_size" />

We use android:fontFamily="@font/ritaric" for apply font on EditText.

查看更多
登录 后发表回答