代码之家  ›  专栏  ›  技术社区  ›  Andrès Mauricio Peña Carmona

Android:当我使用自定义字体时,TextView是重复的

  •  0
  • Andrès Mauricio Peña Carmona  · 技术社区  · 10 年前

    我想为我的android应用程序使用自定义字体,但我有一个问题。 我需要显示自定义字体,但应用程序显示两个文本,一个具有默认字体系列,另一个具有自定义字体系列。。。它似乎复制了我的文本视图

    我遵循了本教程: http://blog.goyello.com/2014/08/01/how-to-use-custom-fonts-in-android-apps-and-not-get-fat-3/

    然而,我也尝试在我的活动的onCreate函数中使用以下代码:

    TextView txt = (TextView) findViewById(R.id.bloodmatesIntro1);
    Typeface font = Typeface.createFromAsset(getAssets(), "BaroqueScript.ttf");
    txt.setTypeface(font);
    

    以及xml文件上的代码

    <TextView
     android:id="@+id/bloodmatesIntro1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_gravity="center_horizontal"
     android:text="@string/bloodmates_intro_1"/>
    

    怎么了?

    编辑:

    我发现下一个代码(由facebook提供)产生了我的问题 https://developers.facebook.com/docs/android/login-with-facebook#step1 :

    if (savedInstanceState == null) {
        // Add the fragment on initial activity setup
        mainFragment = new MainFragment();
        getSupportFragmentManager()
                .beginTransaction()
                .add(android.R.id.content, mainFragment)
                .commit();
    } else {
        // Or set the fragment from restored state info
        mainFragment = (MainFragment) getSupportFragmentManager()
                .findFragmentById(android.R.id.content);
    }
    

    如何在同一活动中使用自定义字体并登录facebook?

    1 回复  |  直到 10 年前
        1
  •  0
  •   Andrès Mauricio Peña Carmona    10 年前

    问题出在片段中,我不知道为什么它会复制元素,所以我没有创建MainFragment类,而是遵循本教程 http://examples.javacodegeeks.com/core-java/android-facebook-login-example/

    现在,我可以在同一活动中使用自定义字体和facebook登录。