React-native Android Splashscreen-自定义字体

时间:2018-10-09 08:34:02

标签: android android-layout react-native splash-screen

我为我的react-native应用程序创建了一个启动画面,并且必须使用自定义字体来实现TextView。 我使用res / layout / launch_screen.xml创建了一个专门用于初始屏幕的Android布局,并且出现了TextViews,但没有自定义字体,然后在splashActivity文件上启动了它。 但这很奇怪,因为当我直接在mainActivity文件上注入布局时,字体似乎已加载。 所以我认为这是由于SplashActivity文件中的字体路径引起的,但是代码似乎还可以。

以下是文件:

SplashActivity.js:


    package com.app;

    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.widget.TextView;
    import android.graphics.Typeface;
    import android.content.res.AssetManager;

    public class SplashActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.launch_screen);

            TextView txt_1 = (TextView) findViewById(R.id.din_bold);
            Typeface font_1 = Typeface.createFromAsset(getAssets(), "fonts/DinCondBold.otf");
            txt_1.setTypeface(font_1);

            TextView txt_2 = (TextView) findViewById(R.id.din_light);
            Typeface font_2 = Typeface.createFromAsset(getAssets(), "fonts/DinCondLight.otf");
            txt_2.setTypeface(font_2);

            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();

        }
    }

MainActivity.js


    package com.app;

    import android.app.Activity;
    import com.facebook.react.ReactActivity;
    import android.os.Bundle;
    import org.devio.rn.splashscreen.SplashScreen;

    public class MainActivity extends ReactActivity {
        @Override
          protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            SplashScreen.show(this, R.style.SplashScreenTheme);

          }
        /**
         * Returns the name of the main component registered from JavaScript.
         * This is used to schedule rendering of the component.
         */
        @Override
        protected String getMainComponentName() {
            return "app";
        }
    }

和launch_screen.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:gravity="center"
    android:orientation="vertical"
    tools:context="com.mitsu.MainActivity">

    <TextView
        android:id="@+id/din_bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SCAN PRODUITS"
        android:textColor="#eb212e"
        android:textSize="36sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/din_light"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="BIENVENUE"
        android:textColor="#717171"
        android:textSize="36sp" />

    <ImageView
        android:layout_width="180dp"
        android:layout_height="180dp"
        android:layout_marginTop="14dp"
        android:src="@drawable/splash_logo" />

</LinearLayout>

有人知道发生了什么事吗?

0 个答案:

没有答案