Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding android.R resources in Android Studio 1.3+ autocomplete

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

The project I'm working on is an Industry project and rarely requires me to use R resources.

enter image description here

like image 503
Machado Avatar asked May 29 '15 12:05

Machado


People also ask

Why is auto complete not working in Android Studio?

if the autocomplete isn't working for you in Android Studio, just press File and uncheck the Power save mode, it should work fine after that. if power save mode is already unchecked then first check then uncheck them.

Where do I put resources in Android Studio?

Change your resource directory By default, your resources are located in module-name /src/ source-set-name /res/ . For example, resources for your module's main source set are in src/main/res/ and resources for the debug source set are in src/debug/res/ .

What is res folder in Android?

The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.

What is resource value in Android Studio?

Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more.


2 Answers

Looking through the AS's 'Code Completion' section, I didn't find any setting which allows to hide the SDK resources and use the app/lib resources instead:

enter image description here

The recently implemented feature, mentioned by StefMa, probably will not help you as it works the other way: it allows library developers to hide some of the resources from the aar package and show only selected portion of resources, aka public recources. Chris Banes made a good intro in this feature here.

like image 154
aga Avatar answered Oct 20 '22 03:10

aga


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
<resources>
    <public type="drawable" name="btn_login"/>
</resources>
  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.
like image 31
Jeroen Mols Avatar answered Oct 20 '22 03:10

Jeroen Mols