Can't convert to color: type=0x2 error when inflating layout in fragment but only on Samsung Galaxy and Note 4

后端 未结 4 1803
予麋鹿
予麋鹿 2020-12-05 17:25

I am working on a simple app with an activity and i use fragments.One screen with some elements. When i compile and run the app it works fine, except on Samsung Galaxy s3 an

相关标签:
4条回答
  • 2020-12-05 17:40

    I faced the same issue, that was caused by using attributes as a reference to color in an XML drawable.

    As mentioned here on API < 21 you can't use attrs to color in the XML drawable. So only way is to use a reference to a color resource (@color/YOURS_COLOR) or use #RGB format.

    So if you want to use an XML drawable with theme depended colors you should create a drawable for each theme.

    0 讨论(0)
  • 2020-12-05 17:43

    Change "AppTheme" to not use Material. For example try:

    <style name="AppTheme" parent="android:Theme.Holo">
    
    </style>
    

    I had a very similar issue on my Samsung Galaxy Tab Pro 8.4 Running Android 4.2. It worked when I changed Styles.xml to use "android:Theme.Holo" or "Theme.AppCompat.Light.DarkActionBar".

    I haven't been able to find any information on exactly why this happens, and why it seems to only affect Samsung products. If you really want to include Material as a style, you could try adding another style file to use with devices that have API level 21 or higher. More info on that is here under the section "Select a theme based on platform version"

    Please keep us updated if you find any other fixes.

    0 讨论(0)
  • 2020-12-05 17:47

    I had the same problem on API 10 devices and it was caused by using theme for API 11+ (from appcompat). For quick solution you may find the following themes declaration in styles.xml

    <style name="AppBaseTheme" parent="...">
    ...
    <style name="AppTheme" parent="...">
    

    And change on:

    <style name="AppBaseTheme" parent="android:Theme.Light">
    ...
    <style name="AppTheme" parent="android:Theme.Light">
    
    0 讨论(0)
  • 2020-12-05 18:00

    I ran into this when using 3rd party lib https://github.com/hoang8f/android-flat-button after I upgraded gradle to 3.0.1.

    Not ideal, but downgrading gradle seemed to resolve the error

    This change requires updating 2 files:

    1. Project build.gradle with

      com.android.tools.build:gradle:2.3.3

    2. gradle/wrapper/gradle-wrapper.properties with

      distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

    0 讨论(0)
提交回复
热议问题