AS升级到3.1.1之后【ZXingScannerView 二维码扫描】error: resource android:attr/font报错VariationSettings not

一、异常:error: resource android:attr/font报错VariationSettings not

原因:开始Google都是让添加代码到什么platform/android下的gradle文件中,找来找去就是找不到这个目录,就更找不到之下的gradle文件了。

解决:在app的build.gradle中添加

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}

AS升级到3.1.1之后【ZXingScannerView 二维码扫描】error: resource android:attr/font报错VariationSettings not_第1张图片

温馨提示:这个v4包的版本你可以直接修改,但是不能是28,我在报错的时候看了下默认设置的就是28,结果GG了,改成24或者27都是OK的。 

二、ZXingScannerView 的使用

佳姝1:添加依赖

implementation 'me.dm7.barcodescanner:zxing:1.9.13 

佳姝2:添加相机权限

佳姝3:activity_zxcsan_view.xml




    

    

佳姝4:自定义NavigationView  【作用与ToolBar一致】

package com.dintech.esl.terminal.view.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dintech.esl.terminal.BuildConfig;
import com.dintech.esl.terminal.R;
import com.dintech.esl.terminal.constant.Conf;
import com.dintech.esl.terminal.utils.Util;
import com.dintech.esl.terminal.view.ZXScanActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NavigationView extends RelativeLayout {

    @BindView(R.id.naviWifiName)
    TextView wifiName;

    @BindView(R.id.naviImage)
    ImageView naviImage;

    @BindView(R.id.naviVersion)
    TextView naviVersion;

    //    @BindView(R.id.naviLogoutButton)
    public ImageView naviLogoutButton;

    @BindView(R.id.naviTextView)
    TextView naviTextView;

    @BindView(R.id.img_wifi)
    ImageView imgWifi;

    private boolean isBacked;
    Context context;

    public NavigationView(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public NavigationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    private void init() {
        View rootV = LayoutInflater.from(getContext()).inflate(R.layout.custom_navigation_layout, this);
        ButterKnife.bind(this, rootV);
        naviLogoutButton = (ImageView) rootV.findViewById(R.id.naviLogoutButton);
        naviTextView.setText("  (V" + Util.getLocalVersionName(getContext()) + ")" +
                                              "-" + (BuildConfig.DEBUG ? "debug" : "release"));
        naviImage.setBackgroundResource(isBacked ?
                                   R.mipmap.abc_cab_ic_comback : R.mipmap.abc_cab_ic_logo_ahp);
        onResumeWifi();
    }

    public void onResumeWifi() {
        wifiName.setText(Util.getWifiName().substring(1, Util.getWifiName().length() - 1));
    }

    @OnClick({R.id.naviLayout, R.id.naviLogoutButton})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.naviLayout:
                if (isBacked) ((Activity) getContext()).finish();
                break;

            case R.id.naviLogoutButton:
                if (isBacked) {
                    naviLogoutButton.setBackgroundResource(R.mipmap.abc_cab_ic_scan);
                    ((Activity) context).startActivityForResult(new Intent(context, 
                                                                  ZXScanActivity.class), 110);
                } else {
                    naviLogoutButton.setBackgroundResource(R.mipmap.abc_cab_navigator_logout);
                    logout();
                }
                break;
        }
    }

    public void setNaviTitle(String title) {
        if (naviVersion != null) {
            naviVersion.setText(title);
            naviVersion.setTextSize(18);
        }
    }

    public void setOnBackClickListener(boolean isBacked) {
        this.isBacked = isBacked;
        wifiName.setVisibility(isBacked ? GONE : VISIBLE);
        imgWifi.setVisibility(isBacked ? GONE : VISIBLE);
        naviTextView.setVisibility(isBacked ? GONE : VISIBLE);
        naviImage.setBackgroundResource(R.mipmap.abc_cab_ic_comback);
        naviLogoutButton.setBackgroundResource(R.mipmap.abc_cab_ic_scan);
    }

    private void logout() {
        new AlertDialog
                .Builder(getContext())
                .setTitle(Conf.NAVIGATION_AD_TITLE)
                .setMessage(Conf.NAVIGATION_AD_MESSAGE)
                .setNegativeButton(Conf.NAVIGATION_AD_NEGATIVE, (dialog, which) -> dialog.dismiss())
                .setPositiveButton(Conf.NAVIGATION_AD_POSITIVE, (dialog, which) -> {
                    android.os.Process.killProcess(android.os.Process.myPid());
                })
                .create()
                .show();
    }
}

佳姝5:ZXScanViewActivity

package com.dintech.esl.terminal.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.dintech.esl.terminal.R;
import com.dintech.esl.terminal.view.widget.NavigationView;
import com.google.zxing.Result;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.dm7.barcodescanner.zxing.ZXingScannerView;

public class ZXScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {

    @BindView(R.id.zx_capture)
    ZXingScannerView mScannerView;

    @BindView(R.id.naviTitle)
    NavigationView naviTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mScannerView = new ZXingScannerView(this);
        setContentView(R.layout.activity_zxscan_view);
        ButterKnife.bind(this);
        naviTitle.setNaviTitle("扫一扫");
        naviTitle.setOnBackClickListener(true);
        naviTitle.naviLogoutButton.setVisibility(View.GONE);
        mScannerView.setAutoFocus(true);
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(this);
        mScannerView.startCamera();
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();
    }

    @Override
    public void handleResult(Result rawResult) {
        Intent intent = new Intent();
        intent.putExtra("results", rawResult.getText());
        setResult(RESULT_OK, intent);
        finish();
    }
}

 //回传

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        String result = data.getStringExtra("results");
        if (deviceEditText.hasFocus()) {
            deviceEditText.setText(result);
            commondityEditText.requestFocus();
        } else if (commondityEditText.hasFocus()) {
            commondityEditText.setText(result);
        }
    }
}

此文章仅自己记录,如想借鉴请点赞 ~~

你可能感兴趣的:(AS升级到3.1.1之后【ZXingScannerView 二维码扫描】error: resource android:attr/font报错VariationSettings not)