Android XML: RuntimeException: Failed to resolve attribute at index 6

后端 未结 10 1895
梦如初夏
梦如初夏 2020-12-01 23:44

Hello dear stackoverflower,

In my project, i am using the new \"android design library\". The problem is, that there is a runtime exception which says(Im trying to c

相关标签:
10条回答
  • 2020-12-01 23:44

    In case anybody comes across this while setting up Android TV / working alongside the AndroidTV sample code, then the solution is to add the leanback theme to your activities in the manifest

    <activity
      android:name=".PlaybackActivity"
      android:theme="@style/Theme.Leanback" />
    
    0 讨论(0)
  • 2020-12-01 23:48

    You can solved this problem by using Theme.AppCompat.Light as your activity's parent theme. add: The reason is that one of the default style using inner in FloatingActionButton is declare like this: the backgroundTint is refer to another attribute colorAccent which should be measure declared in our theme, otherwise, the exception might be throw. But colorAccent is declared in AppCompat Theme and did not declared in the sdk default Theme.To measure that we can using the design lib correctly in running, one of the easy way is to measure the using of AppCompat Theme like Theme.AppCompat.Light.

    0 讨论(0)
  • 2020-12-01 23:48

    This is because of more than one style.xml files.

    Add below line in your app build.gradle file:

    compile 'com.android.support:design:22.2.0'
    
    0 讨论(0)
  • 2020-12-01 23:48

    I came across this problem as I create my custom view with a custom attribute, but using applicationContext. I think that the application context misses my attribute's information. Changing to the activity's context fixed my problem here.

    0 讨论(0)
  • 2020-12-01 23:49

    For my case, this issue started showing up after migrating to AndroidX. The scenario was I implemented custom views that extends AppCompatEditText and set custom styles as well. I ran into this issue while running the unit tests.

    The error logs show this as the root cause:

    Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0300f9 a=2}
        at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
    

    In the styles I was using Base.Widget.AppCompat.EditText:

    <style name="MyEditText" parent="Base.Widget.AppCompat.EditText">
        <item name="android:fontFamily">...</item>
        <item name="android:textSize">...</item>
    </style>
    

    Changing the parent to Android's base android:Widget.EditText removed the error and didn't change any behavior/UI for me.

    It's strange since digging through the inheritance structure of Base.Widget.AppCompat.EditText, the root parent is also android:Widget.EditText.

    0 讨论(0)
  • 2020-12-01 23:57

    Ran into this problem myself. It's because my app isn't using AppCompat yet, still just the regular support FragmentActivity. This means that FloatingActionButton was looking for two theme attributes and it couldn't find them.

    Specifically adding in these missing attributes made it work for me without the need to start using AppCompat.

    <LinearLayout
        ...
        xmlns:app="http://schemas.android.com/apk/res-auto" 
        .../>
    
        <android.support.design.widget.FloatingActionButton
            ...
            app:backgroundTint="@color/{some color statelist}"
            app:rippleColor="@color/{some color statelist}"
            ... />
    
    </LinearLayout>
    
    0 讨论(0)
提交回复
热议问题