应用程序每次启动时都会崩溃而不会出现任何错误

时间:2014-03-25 13:15:31

标签: android

我正在尝试将this 代码实现到我的应用程序并在assets/fonts中使用我的字体。我没有在logcat中得到任何异常但是每次都启动它。它崩溃了。什么是我做错了

这是mycode

public class appp  extends Application {
      private Typeface normalFont;
        private Typeface boldFont;



        // -- Fonts -- //
        public void setTypeface(TextView textView) {
            if(textView != null) {
                if(textView.getTypeface() != null && textView.getTypeface().isBold()) {
                    textView.setTypeface(getBoldFont());
                } else {
                    textView.setTypeface(getNormalFont());
                }
            }
        }

        private Typeface getNormalFont() {
            if(normalFont == null) {
                normalFont = Typeface.createFromAsset(getAssets(),"fonts/SERSAL.ttf");
            }
            return this.normalFont;
        }

        private Typeface getBoldFont() {
            if(boldFont == null) {
                boldFont = Typeface.createFromAsset(getAssets(),"fonts/Cheboyga.ttf");
            }
            return this.boldFont;
        }

}

这是主类

appp  application = (appp) getApplication();
        TextView myTextView = (TextView) findViewById(R.id.my_textview);
        application.setTypeface(myTextView);

3 个答案:

答案 0 :(得分:0)

您可以像这样设置类型面:

 Typeface font;
 font = Typeface.createFromAsset(getActivity().getAssets(), "xxx.ttf"); 
 TextView myTextView = (TextView) findViewById(R.id.my_textview);
 myTextView.setTypeface(font);   

你能检查一下这应该有用吗,

答案 1 :(得分:0)

每个应用程序都有自己的清单文件,其中包含唯一的包名称。

您应该将每个应用视为唯一。

与app1类似,您可能有 -

package="com.package.app1"

要使用 -

访问包名称
public String getAppName()
{
    final PackageManager pm = getApplicationContext().getPackageManager();


    ApplicationInfo ai;
    try {
        ai = pm.getApplicationInfo( getApplicationContext().getPackageName(), 0);
    } catch (final NameNotFoundException e) {
        ai = null;
    }
    final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");

    return applicationName;
}

同样适用于应用程序标签..

<application android:name="com.package.app1.app"> ... </application>

答案 2 :(得分:0)

您正在使用自定义应用程序,因此您可以进行delcare

您的清单中的

android:name="your packagename.appp"

相关问题