Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在为Android设置Roboto时遇到问题,是什么导致了膨胀错误?_Java_Android_Fonts - Fatal编程技术网

Java 在为Android设置Roboto时遇到问题,是什么导致了膨胀错误?

Java 在为Android设置Roboto时遇到问题,是什么导致了膨胀错误?,java,android,fonts,Java,Android,Fonts,我是Android开发的新手,我正在尝试为运行在API 11上的应用程序获取Roboto字体。目前,它在logcat中给了我一个错误,说在膨胀类时出错 LogCat报告: 08-04 02:45:53.264: E/AndroidRuntime(2595): FATAL EXCEPTION: main 08-04 02:45:53.264: E/AndroidRuntime(2595): Process: com.example.sportsocialv2, PID: 2595 08-04 02

我是Android开发的新手,我正在尝试为运行在API 11上的应用程序获取Roboto字体。目前,它在logcat中给了我一个错误,说在膨胀类时出错

LogCat报告:

08-04 02:45:53.264: E/AndroidRuntime(2595): FATAL EXCEPTION: main
08-04 02:45:53.264: E/AndroidRuntime(2595): Process: com.example.sportsocialv2, PID: 2595
08-04 02:45:53.264: E/AndroidRuntime(2595): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sportsocialv2/sportsocialv2.activity.LoginActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class com.sportsocialv2.theme.TextView_Roboto
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.os.Handler.dispatchMessage(Handler.java:102)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.os.Looper.loop(Looper.java:136)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.ActivityThread.main(ActivityThread.java:5017)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at java.lang.reflect.Method.invokeNative(Native Method)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at java.lang.reflect.Method.invoke(Method.java:515)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at dalvik.system.NativeStart.main(Native Method)
08-04 02:45:53.264: E/AndroidRuntime(2595): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class com.sportsocialv2.theme.TextView_Roboto
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.inflate(LayoutInflater.java:462)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.Activity.setContentView(Activity.java:1929)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at sportsocialv2.activity.LoginActivity.onCreate(LoginActivity.java:78)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.Activity.performCreate(Activity.java:5231)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
08-04 02:45:53.264: E/AndroidRuntime(2595):     ... 11 more
08-04 02:45:53.264: E/AndroidRuntime(2595): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sportsocialv2.theme.TextView_Roboto" on path: DexPathList[[zip file "/data/app/com.example.sportsocialv2-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.sportsocialv2-2, /vendor/lib, /system/lib]]
08-04 02:45:53.264: E/AndroidRuntime(2595):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
08-04 02:45:53.264: E/AndroidRuntime(2595):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
这是我想要的Roboto fontstyle的活动:

<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="sportsocialv2.activity.LoginActivity"
>

<!-- Login progress -->

<LinearLayout
    android:id="@+id/login_status"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:visibility="gone" >

    <com.sportsocialv2.theme.TextView_Roboto
                    android:id="@+id/settings_cover_tv" 
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="16sp"
                    android:layout_marginLeft="10dp"
                    />

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp" />

    <TextView
        android:id="@+id/login_status_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:fontFamily="sans-serif-light"
        android:text="@string/login_progress_signing_in"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

<!-- Login form -->

<ScrollView
    android:id="@+id/login_form"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        style="@style/LoginFormContainer"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/enter_username_prompt"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:singleLine="true" />

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/prompt_password"
            android:imeActionId="@+id/login"
            android:imeActionLabel="@string/action_sign_in_short"
            android:imeOptions="actionUnspecified"
            android:inputType="textPassword"
            android:maxLines="1"
            android:singleLine="true" />

        <Button
            android:id="@+id/sign_in_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginTop="16dp"
            android:paddingLeft="32dp"
            android:paddingRight="32dp"
            android:text="@string/action_sign_in_register" />
    </LinearLayout>
</ScrollView>
我已经在SO和其他网站上搜索了关于设置Roboto的指南,但我似乎无法运行或实际显示字体


感谢advanced提供的所有建议。

似乎您使用了错误的软件包名称。sportsocialv2.theme.TextView_Roboto在xml文件中为相应的TextView使用此选项。
package sportsocialv2.theme;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

public class TextView_Roboto extends TextView
{
    public TextView_Roboto(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        createFont();
    }

    public TextView_Roboto(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        createFont();
    }

    public TextView_Roboto(Context context)
    {
        super(context);
        createFont();
    }

    public void createFont()
    {
        Typeface font = Typeface.createFromAsset(getContext().getAssets(), "Roboto-Regular.ttf");

        setTypeface(font);
    }
}