简体   繁体   English

将minSdkVersion从15更改为16

[英]Changing minSdkVersion from 15 to 16

When I changed my minSdkVersion then I am getting this error: 当我更改我的minSdkVersion然后我收到此错误:

android.view.InflateException: Binary XML file line #43: Error inflating class TextView android.view.InflateException:二进制XML文件行#43:错误膨胀类TextView

Eariler it was working fine before I have made the changes. 在我做出改变之前,它的工作正常。

Here is my style : 这是我的风格:

<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>

I guess there is something wrong with the parent property of a style. 我想样式的父属性有问题。

如果您正在更改您的版本,那么还要更改支持库。您必须更改支持库,例如,对于egfor api 23,您必须将appcompact库版本更改为23.希望此帮助。:)

You should try changing 你应该尝试改变

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

to

<style name="AlertDialogCustom" parent="Theme.AppCompat.Dialog">

This is the issue with your font family which you are using in style. 这是您正在使用的字体系列的问题。 May be sans-serif-light font is not available in your assests>>fonts folder. 您的assests >> fonts文件夹中可能没有sans-serif-light字体。 So check with this how to use custom fonts in android. 所以请查看如何在android中使用自定义字体。

Here are the steps to follow: 以下是要遵循的步骤:

Android Studio: Android Studio:

Step1: Adding font family files to app 第1步:将字体系列文件添加到应用程序

A) Go to the (project folder) A)转到(项目文件夹)

B) Then app>src>main B)然后app> src> main

C) Create folder 'assets>fonts' into the main folder. C)在主文件夹中创建文件夹'assets> fonts'。

D) Put your 'abc.ttf' or 'abc.otf' font file into the fonts folder. D)将'abc.ttf'或'abc.otf'字体文件放入fonts文件夹中。

Step 2: Now Create attrs.xml under res folder if it's not exists and add declare-styleable 第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>

//Here FuturaLT/FuturaLT_Heavy/FuturaLT_Light are file names //这里的FuturaLT / FuturaLT_Heavy / FuturaLT_Light是文件名

Note: – enum name should be font type name with underscore(_) uses, it will be easy for you to understand font family usage in your native code. 注意: - 枚举名称应该是下划线(_)使用的字体类型名称,您可以很容易地理解本机代码中的字体系列用法。 No special character or other letter, otherwise you will got error in gen folder for same attribute id. 没有特殊字符或其他字母,否则你会在gen文件夹中获得相同属性id的错误。

Step 3: Create your custom view(Button, TextView, EditText) class:- 第3步:创建自定义视图(Button,TextView,EditText)类: -

package com.myapp.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.TextView;

import com.myapp.R;

public class CustomTextView extends TextView  {

    public CustomTextView(Context context) {
        super(context);
    }

    public CustomTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        try {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Font);
            int font = a.getInt(R.styleable.Font_typeface, 0);
            a.recycle();
            String str;
            switch (font) {
                case 1:
                    str = "fonts/FuturaLT.otf";
                    break;
                case 2:
                    str = "fonts/FuturaLT_Heavy.otf";
                    break;
                case 3:
                    str = "fonts/FuturaLT_Light.otf";
                    break;
                default:
                    str = "fonts/FuturaLT.otf";
                    break;
            }

            setTypeface(FontManager.getInstance(getContext()).loadFont(str));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("unused")
    private void internalInit(Context context, AttributeSet attrs) {

    }
}

Step 4: Add FontManager.java support class 第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);
    }
}

Step 5: Usage in XML layout 第5步:在XML布局中使用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.myapp.views.CustomTextView
        android:id="@+id/tv_time_slot"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        app:typeface="FuturaLT" />
</LinearLayout>

You can also use in java code directly: 您也可以直接在java代码中使用:

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/FuturaLT.ttf");
tvText.setTypeface(tf);

Note:- If you don't use here FontManager to apply typeface and directly use then you are not able to see your views in graphics preview. 注意: -如果您不使用FontManager应用字体并直接使用,那么您将无法在图形预览中看到您的视图。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将FireSD的MinSDKVersion从15正确更改为16 - How to correctly change MinSDKVersion from 15 to 16 for firebase 将Android minSdkVersion 15更改为19的后果 - Consquences of changing Android minSdkVersion 15 to 19 Android、Firebase:minSdkVersion 15 不能小于版本 16 - Android, Firebase: minSdkVersion 15 cannot be smaller than version 16 将 minSdkVersion 从 16 更改为 26 将发布 APK 大小从 17 MB 增加到 39 MB - Changing minSdkVersion from 16 to 26 increased release APK size from 17 to 39 MB 将Android minSDKVersion从9中断程序更改为 - Changing Android minSDKVersion from 9 to 10 breaks program 由于minSdkVersion从21更改为14而导致的错误 - Error due to Changing minSdkVersion from 21 to 14 Android、Firebase:清单合并失败:uses-sdk:minSdkVersion 15 不能小于版本 16 - Android, Firebase: Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 16 清单合并失败:uses-sdk:minSdkVersion 15不能小于库中声明的版本16 - Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library uses-sdk:minSdkVersion 15 不能小于库中声明的版本 16 - uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library 错误:从minSdkVersion 16升级到minSdkVersion 23的软件包android.support.multidex不存在 - error: package android.support.multidex does not exist whem upgrading from minSdkVersion 16 to minSdkVersion 23
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM