Android tools:replace的使用

当我们的项目的某些属性和第三方库中属性有冲突或者我们想修改第三方库中某些资源时,我们就需要使用tools:replace来处理。

1、有冲突的情况

比如第三方库中也定义了application@icon application@label属性,则会与你的项目发生冲突。

那么解决的方法就是在你的Application节点中加入tools:replace来表示替换三方库中的相关属性,如下:

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/box_icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        tools:replace="android:icon, android:label">

2、替换三方库中的属性

比如在使用二维码识别的支持库zxing-android-embedded时,需要自定义拍照Activity的屏幕方向,则在AndroidManifest.xml中加入相关的activity节点,并覆盖其属性,xml如下:

   <!--二维码扫描界面 for zxing-android-embedded-->
        <activity
            android:name="com.journeyapps.barcodescanner.CaptureActivity"
            android:screenOrientation="portrait"
            tools:replace="screenOrientation" />

使用tools:replace需要在manifest根节点加上相关的引用,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.bcoder.app">

猜你喜欢

转载自blog.csdn.net/CHS007chs/article/details/85849625