Hiding android.R resources in Android Studio 1.3+ autocomplete

前端 未结 2 709
一整个雨季
一整个雨季 2021-01-17 17:36

Is it possible to configure Android Studio to display only the @drawable resources that are inside the project folder?

The project I\'m

2条回答
  •  生来不讨喜
    2021-01-17 18:06

    I don't think you can do that actually, only library developers can choose to hide the resources in their aar distributions.

    So you are dependent on library developers to do that for you. Luckily the latest Android support library should already have done this for you.

    The way library developers can hide resources in their library is:

    1. Create a new folder on the same level as res called res-public (name not important) with a subfolder called values:
    src
        main
             java
             res
             res-public
                 values
    
    1. In that folder create a new file called public.xml, where you define all resources that you want to have public with their name followed by type
    
        
    
    
    1. Then make sure to reference this new folder in your build.gradle file:
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
    
        sourceSets {
            main.res.srcDirs 'res', 'res-public'
        }
    
        defaultConfig {
           ...
        }
    }
    
    1. Make sure you are using at least version 1.3 of the Gradle plugin
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0'
        }
    }
    
    1. Compile your library into an aar file and include that into your project. Only the btn_login resource will now be visible.
      • Check here how to include a local aar file, so you can test without pushing to a Maven repo.

提交回复
热议问题