Use double quotes by default when importing in Android studio - android-studio

Every time I auto-import stuff using Android Studio, the import is single quoted by default, which is against the linting rules I use. How can I change it that it defaults to importing with double quotes.
For example, instead of:
import 'package:flutter/material.dart';
I would like that auto-import generate this line by default:
import "package:flutter/material.dart";

Related

Why does Android Studio show import... vs. the actual import statements

I am new to Android development.
At various times I have noticed that the top of a Kotlin file shows import... and I have to click it each time to display the actual import directives.
What is that behavior? Why do the import directives not just display each time I open the file?
They're collapsed to reduce clutter so you can focus on the code itself. Most of the time there's no need to deal with the imports directly.
You can change this behavior in Settings -> Editor -> General -> Code folding. Disable "Imports" in the "General" section.

How to import only those functions from module which I am using (pycharm)

import time
time.time()
time.sleep()
So for example I imported time and using only 2 functions from this module. Is there a hotkey or plugin to import only this functions automaticly and pop module name every time I used some function from there, without manually chainging every line.
What I am trying to get is
from time import time,sleep
time()
sleep()
There are different configuration, depending on your needs I suggest you to go through this official JetBrains documentations about
Auto import.
To configure auto-import, in the Settings/Preferences dialog Ctrl+Alt+S
, go to Editor | General | Auto Import, and use the corresponding XML, Python, and TypeScript/JavaScript options.
To enable / change the short cut, do the following:
Go to PyCharm -> Preferences
Check “Show Import Popup”
Next, look up the keyboard shortcut for auto-completion and change it to whatever shortcut you’d like to use.
When you tap this shortcut twice you will get the special auto-import dropdown
Or also
You can define your preferred import style for Python code by using the following options available on the Auto Import page of the project settings (Settings/Preferences | Editor | General | Auto Import).

I can't import android.text.Editable

I've just been to began android app with beginner books
That book use "android text Editable"
cause I tried to import text Editable but i can't it
Then I found:
Why used import statement is specified as "unused import statement" in Android Studio?
As above I removed "Optimize imports on the fly "
But don't disappear yet
Why I can't import android.text.Editable
Someone teach me, please.
just in case I use android studio latest version.

How to control when Imports are replaced by wildcard in Android Studio in Kotlin files

I noticed that for up to 4 imports from the same package, auto-import will simply append the import in the list:
import android.support.v7.widget.AppCompatImageButton
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.Toolbar
But adding a 5th import will make auto-import switch to a wildcard:
import android.support.v7.widget.*
Is there a way to keep auto-import on but tell it to not do that, or change the threshold? I don't mind having a long list of imports, it feels... familiar.
You can set this under the Kotlin "Code Style" section in Preferences:
The Android Kotlin Style Guide says:
Wildcard imports (of any type) are not allowed.
You can set your Android Studio preferences to remove all wildcard imports from Kotlin files.
Open Android Studio Preferences: Editor > Code Style > Kotlin
Select Use single name import for Top-level Symbols
Select Use single name import for Java Statics and Enum Members
Remove all packages from Packages to Use Import with by clicking the minus - symbol until it says Nothing to show

How to auto import the necessary classes in Android Studio with shortcut?

I've just switch to Android Studio 0.5.1, and the things going so slow here, because nothing works in the regular way...
How do I import the necessary classes with shortcut?
I mean like this ones?
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
Go to File -> Settings -> Editor -> Auto Import -> Java and make the below things:
Select Insert imports on paste value to All
Do tick mark on Add unambigious imports on the fly option and "Optimize imports on the fly*
Go on the missing declaration with cursor and press alt+enter
Ctrl + Alt + O to optimize imports
On my Mac Auto import option was not showing it was initially hidden
Android studio ->Preferences->editor->General->Auto Import
and then typed in searched field auto then auto import option appeared.
And now auto import option is now always shown as default in Editor->General.
hopefully this option will also help others.
See attached screenshot
To import classes on the fly :
On OSX press Alt(Option) + Enter.
File -> Settings -> Keymap
Change keymaps settings to your previous IDE to which you are familiar with
You can also use Eclipse's keyboard shortcuts: just go on preferences > keymap and choose Eclipse from the drop-down menu. And all your Eclipse shortcuts will be used in here.
On Windows with Android Studio 1.5.1 :
File --> Settings --> Editor --> General --> Auto Import

Resources