I want to change the button font family. I tried changing it by trying this code:
Button txt = (Button)findViewById(R.id.button1);
Typeface font = Typeface.createFromAsset(getAssets(), "sfont.ttf");
txt.setTypeface(font);
but I get an error, and if I ignored it, the application crashes every time.
This is the layout XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
>
<TextView
android:text="@string/enter"
android:textColor="#000"
android:textSize="16dp"
android:textAlignment="center"
android:id="@+id/**button1**"text1
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="20dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/**text1**" button1
android:padding="30dp"
android:layout_gravity="center"
android:text="@string/entenbut"
/>
PROBLEM SOLVED A problem has occurred in the XML code. Thanks to everyone :)
source
share