Android Studio:字体更改错误

时间:2017-02-07 19:40:34

标签: java android fonts textview

所以我的活动有两个对象,一个TextView和一个Button。我确实使用我的资源文件夹中的字体样式更改了这两者的字体。该项目将很好地加载没有问题。但是现在突然改变TextView字体会导致游戏崩溃并且无法加载。除了可能使用按钮显示文本之外,我无法理解可能导致这种情况以及如何解决这个问题,这是实际的。

我的java代码:

public class Main_Menu extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main__menu);
        Button n=(Button) findViewById(R.id.start_button);
        Typeface typeface = Typeface.createFromAsset(getAssets(), "Stencil WW.ttf");
        n.setText("Start");
        n.setTypeface(typeface);
        Typeface typeface2 = Typeface.createFromAsset(getAssets(), "Stencil WW.ttf");
        TextView title = (TextView) findViewById(R.id.title);
        title.setTypeface(typeface2);
        //sets screen orientation on created
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        MediaPlayer mMediaPlayer = new MediaPlayer();
        mMediaPlayer = MediaPlayer.create(this, R.raw.sound1);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setLooping(true);
        mMediaPlayer.start();
    }
}

我确实使用了字体来更改两种文本字体,但我尝试使用typeface2再次制作它仍然会崩溃。不确定我是否需要显示我的项目的任何其他部分,但如果您希望看到它。谢谢你的帮助。

enter image description here

1 个答案:

答案 0 :(得分:0)

好像你忘记了" setText"标题

相关问题