【发布时间】:2015-05-05 13:15:18
【问题描述】:
我想更改按钮的字体系列。我试图改变它尝试这段代码:
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 代码中存在问题 谢谢大家:)
【问题讨论】:
-
您介意与我们分享异常的堆栈跟踪吗?
-
对不起,我怎样才能得到异常的堆栈跟踪?这是我的第一个应用程序:)
-
查看logcat的内容
-
这就是你可以在预览中看到的:app.box.com/s/zst4c76cwzwiteqq5tdtvcvy7sgleeyc
-
为什么要将
AppCompatTextView转换为Button?
标签: java android android-studio