Android 将版本从15更改为16

Android 将版本从15更改为16,android,Android,当我更改minsdk版本时,出现以下错误: android.view.InflateException:二进制XML文件行#43:膨胀类TextView时出错 在我做出改变之前,它工作得很好 这是我的风格: <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- All customizations that are NOT specific to a particula

当我更改minsdk版本时,出现以下错误:

android.view.InflateException:二进制XML文件行#43:膨胀类TextView时出错

在我做出改变之前,它工作得很好

这是我的风格:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/white</item>
        <item name="colorControlNormal">@color/greyDark</item>
        <item name="colorControlActivated">@color/off_white</item>
        <item name="android:windowBackground">@color/pink</item>
        <item name="android:fontFamily">sans-serif-light</item>
        <item name="android:textStyle">normal</item>
        <item name="android:windowContentTransitions" tools:targetApi="lollipop">true</item>
        <item name="android:windowAllowEnterTransitionOverlap" tools:targetApi="lollipop">true</item>
        <item name="android:windowAllowReturnTransitionOverlap" tools:targetApi="lollipop">true</item>
        <item name="android:windowSharedElementEnterTransition" tools:targetApi="lollipop">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition" tools:targetApi="lollipop">@android:transition/move</item>

    </style>
    <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
        <item name="android:textColor">@color/pink</item>
        <item name="android:typeface">normal</item>
        <item name="android:height">5dp</item>
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:background">@color/white</item>
    </style>

@颜色/原色
@颜色/原色/深色
@颜色/白色
@颜色/灰色
@颜色/灰白色
@颜色/粉红色
无衬线灯
正常的
真的
真的
真的
@android:过渡/移动
@android:过渡/移动
@颜色/粉红色
正常的
5dp
20便士
大胆的
@颜色/白色

我猜某个样式的父属性有问题。

如果要更改版本,请同时更改支持库。您必须更改支持库,例如,对于api 23,您必须将appcompact库版本更改为23。
希望有此帮助。

如果要更改版本,请同时更改支持库。您必须更改支持库,例如,对于api 23,您必须将appcompact库版本更改为23。
希望对您有所帮助。:

您应该尝试更改

<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">


您应该尝试更改

<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">


这是您在样式中使用的字体系列的问题。可能是无衬线浅色字体在Assets>>字体文件夹中不可用。因此,请检查一下如何在android中使用自定义字体

以下是要遵循的步骤:

安卓工作室:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/white</item>
        <item name="colorControlNormal">@color/greyDark</item>
        <item name="colorControlActivated">@color/off_white</item>
        <item name="android:windowBackground">@color/pink</item>
        <item name="android:fontFamily">sans-serif-light</item>
        <item name="android:textStyle">normal</item>
        <item name="android:windowContentTransitions" tools:targetApi="lollipop">true</item>
        <item name="android:windowAllowEnterTransitionOverlap" tools:targetApi="lollipop">true</item>
        <item name="android:windowAllowReturnTransitionOverlap" tools:targetApi="lollipop">true</item>
        <item name="android:windowSharedElementEnterTransition" tools:targetApi="lollipop">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition" tools:targetApi="lollipop">@android:transition/move</item>

    </style>
    <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
        <item name="android:textColor">@color/pink</item>
        <item name="android:typeface">normal</item>
        <item name="android:height">5dp</item>
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:background">@color/white</item>
    </style>
步骤1:将字体系列文件添加到应用程序

A) 转到(项目文件夹)

B) 然后是app>src>main

C) 在主文件夹中创建文件夹“资产>字体”

D) 将“abc.ttf”或“abc.otf”字体文件放入字体文件夹

步骤2: 现在在res文件夹下创建attrs.xml(如果不存在),并添加declare styleable

<?xml version="1.0" encoding="utf-8"?>
<resources>

<declare-styleable name="Font">
<attr name="typeface">
<enum name="FuturaLT" value="0" />
<enum name="FuturaLT_Heavy" value="1" />
<enum name="FuturaLT_Light" value="2" />
</attr>
</declare-styleable>

</resources>
步骤4:添加FontManager.java支持类

package com.myapp.views;

import android.content.Context;
import android.graphics.Typeface;

import java.util.HashMap;
import java.util.Map;

public class FontManager {
    private Map<String, Typeface> fontCache = new HashMap<String, Typeface>();
    private static FontManager instance = null;
    private Context mContext;

    private FontManager(Context mContext2) {
        mContext = mContext2;
    }

    public synchronized static FontManager getInstance(Context mContext) {
        if (instance == null) {
            instance = new FontManager(mContext);
        }
        return instance;
    }

    public Typeface loadFont(String font) {
        if (false == fontCache.containsKey(font)) {
            fontCache.put(font, Typeface.createFromAsset(mContext.getAssets(), font));
        }
        return fontCache.get(font);
    }
}
注意:-如果不在此处使用FontManager应用字体并直接使用
然后您将无法在图形预览中查看视图。

这就是您在样式中使用的字体系列的问题。可能是无衬线浅色字体在Assets>>字体文件夹中不可用。因此,请检查一下如何在android中使用自定义字体

以下是要遵循的步骤:

安卓工作室:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/white</item>
        <item name="colorControlNormal">@color/greyDark</item>
        <item name="colorControlActivated">@color/off_white</item>
        <item name="android:windowBackground">@color/pink</item>
        <item name="android:fontFamily">sans-serif-light</item>
        <item name="android:textStyle">normal</item>
        <item name="android:windowContentTransitions" tools:targetApi="lollipop">true</item>
        <item name="android:windowAllowEnterTransitionOverlap" tools:targetApi="lollipop">true</item>
        <item name="android:windowAllowReturnTransitionOverlap" tools:targetApi="lollipop">true</item>
        <item name="android:windowSharedElementEnterTransition" tools:targetApi="lollipop">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition" tools:targetApi="lollipop">@android:transition/move</item>

    </style>
    <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
        <item name="android:textColor">@color/pink</item>
        <item name="android:typeface">normal</item>
        <item name="android:height">5dp</item>
        <item name="android:textSize">20sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:background">@color/white</item>
    </style>
步骤1:将字体系列文件添加到应用程序

A) 转到(项目文件夹)

B) 然后是app>src>main

C) 在主文件夹中创建文件夹“资产>字体”

D) 将“abc.ttf”或“abc.otf”字体文件放入字体文件夹

步骤2: 现在在res文件夹下创建attrs.xml(如果不存在),并添加declare styleable

<?xml version="1.0" encoding="utf-8"?>
<resources>

<declare-styleable name="Font">
<attr name="typeface">
<enum name="FuturaLT" value="0" />
<enum name="FuturaLT_Heavy" value="1" />
<enum name="FuturaLT_Light" value="2" />
</attr>
</declare-styleable>

</resources>
步骤4:添加FontManager.java支持类

package com.myapp.views;

import android.content.Context;
import android.graphics.Typeface;

import java.util.HashMap;
import java.util.Map;

public class FontManager {
    private Map<String, Typeface> fontCache = new HashMap<String, Typeface>();
    private static FontManager instance = null;
    private Context mContext;

    private FontManager(Context mContext2) {
        mContext = mContext2;
    }

    public synchronized static FontManager getInstance(Context mContext) {
        if (instance == null) {
            instance = new FontManager(mContext);
        }
        return instance;
    }

    public Typeface loadFont(String font) {
        if (false == fontCache.containsKey(font)) {
            fontCache.put(font, Typeface.createFromAsset(mContext.getAssets(), font));
        }
        return fontCache.get(font);
    }
}
注意:-如果不在此处使用FontManager应用字体并直接使用

然后,您将无法在图形预览中查看视图。

否我的appcompact库版本为:compile'com.android.support:appcompat-v7:24.2.1'更改应用程序主题OK,但更改了什么?将应用程序主题更改为浅否我的appcompact库版本为:compile'com.android.support:appcompat-v7:24.2.1'更改应用程序主题正常,但有什么变化?再次将应用程序主题更改为light change misSDKVersion并检查它是否工作?@ReadyAndroid不工作我已经检查了好几次Pratik answer对我没有帮助,因为我已经使用了appcompact版本24.2.1,我正在询问它在任何MindkVersion中工作检查一下这个,如果它不适用,那么请添加错误的xml文件。等一下,我看到了这个外观,我有appcompact版本'com.android.support:appcompat-v7:24.2.1',但我使用的所有样式都很简单,v11,v14,v17所以这很重要,因为之前它没有显示任何error@ReadyAndroid我说na它适用于minsdkVersion 15我测试了再次阅读我的问题更改misSDKVersion并检查它是否有效?@ReadyAndroid无效我已经检查了好几次Pratik答案对我没有帮助,因为我已经使用了appcompact版本24.2.1I我要求在任何Minsdk版本中都检查该版本,如果它不适用于该版本,请添加xml文件以查找错误。等等,我看到了这个外观,我有appcompact版本'com.android.support:appcompat-v7:24.2.1',但我使用的所有样式都很简单,v11,v14,v17所以这很重要,因为之前它没有显示任何error@ReadyAndroid我说不,它是为MinsdkVersion15工作的,我测试了阅读我的问题请看讨论我问了一些问题请看讨论我问了一些问题