我想更改按鈕的字體系列。我試圖改變它嘗試此代碼:android工作室中的按鈕更改字體系列
Button txt = (Button)findViewById(R.id.button1);
Typeface font = Typeface.createFromAsset(getAssets(), "sfont.ttf");
txt.setTypeface(font);
但我收到一個錯誤,如果我忽略它的應用程序每次崩潰。
這是佈局XML代碼:
<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"
/>
問題解決了有一個在XML代碼中的問題 謝謝大家:)
你介意與我們分享異常的堆棧跟蹤嗎? – Blackbelt
對不起,但我怎麼能得到異常的堆棧跟蹤?這是我的第一個應用程序:) –
檢查logcat的 – Blackbelt