在Apptheme中添加样式会使Dialog出现通货膨胀问题

时间:2019-02-10 04:57:50

标签: android android-styles

我想为所有活动设置字体类型,所以我在样式中添加了字体系列项目:-

<style name="AppTheme" parent="Theme.AppCompat.Light">


<item name="android:fontFamily">serif</item>

</style>

然后在放大对话框时发生此错误

2019-02-10 06:45:22.831 5038-5038/com.app.boshra.fragments E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.app.boshra.fragments, PID: 5038
    android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class EditText
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:400)
        at android.app.Dialog.setContentView(Dialog.java:512)
        at com.app.boshra.NovelMessage.Uninterface.dialoge(Uninterface.java:1022)
        at com.app.boshra.NovelMessage.Uninterface.access$1100(Uninterface.java:63)
        at com.app.boshra.NovelMessage.Uninterface$8.onClick(Uninterface.java:284)
        at android.view.View.performClick(View.java:5205)
        at android.view.View$PerformClick.run(View.java:21162)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5452)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:762)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
     Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class EditText
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:400) 
        at android.app.Dialog.setContentView(Dialog.java:512) 
        at com.app.boshra.NovelMessage.Uninterface.dialoge(Uninterface.java:1022) 
        at com.app.boshra.NovelMessage.Uninterface.access$1100(Uninterface.java:63) 
        at com.app.boshra.NovelMessage.Uninterface$8.onClick(Uninterface.java:284) 
        at android.view.View.performClick(View.java:5205) 
        at android.view.View$PerformClick.run(View.java:21162) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5452) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:762) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) 
     Caused by: java.lang.ArrayIndexOutOfBoundsException: length=33; index=429
        at android.content.res.StringBlock.get(StringBlock.java:65)
        at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
        at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:1151)
        at android.content.res.TypedArray.getString(TypedArray.java:195)
        at android.widget.TextView.<init>(TextView.java:1067)
        at android.widget.EditText.<init>(EditText.java:64)
        at android.widget.EditText.<init>(EditText.java:60)
        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:69)
        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:65)
        at android.support.v7.app.AppCompatViewInflater.createEditText(AppCompatViewInflater.java:192)
        at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:114)
        at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
        at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:400) 
        at android.app.Dialog.setContentView(Dialog.java:512) 
        at com.app.boshra.NovelMessage.Uninterface.dialoge(Uninterface.java:1022) 
        at com.app.boshra.NovelMessage.Uninterface.access$1100(Uninterface.java:63) 
        at com.app.boshra.NovelMessage.Uninterface$8.onClick(Uninterface.java:284) 
        at android.view.View.performClick(View.java:5205) 
        at android.view.View$PerformClick.run(View.java:21162) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5452) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:762) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) 

我知道这个错误存在很多问题,但似乎有不同的原因导致此问题,但我的情况没有解决方案。我已经在清单中添加了主题名称,并且当我为对话框XML充气时会显示此错误在Java中

final Dialog d = new Dialog(Uninterface.this);
d.setContentView(R.layout.dialog);//here is where the error happens

仅当我为活动的常规自定义设置任何项目时,才会发生此错误。

0 个答案:

没有答案