Astavie
Astavie

Reputation: 101

How to use 4-space wide tab character in Android Studio?

I'm creating a Flutter app in android studio. Under Settings -> Editor -> Code Style -> Dart, I enabled "use tab character" and changed the tab size and indent to 4.

However, nothing seemed to have changed in the main.dart file, so I used Ctrl-Alt-Shift-L to reformat the code (even tried with "code cleanup" enabled), but it still uses two spaces to indent.

How do I make android studio use tab characters?

Upvotes: 4

Views: 7754

Answers (5)

iOSonntag
iOSonntag

Reputation: 121

You can still change the tab indents by manually editing the configuration files of Android Studio.

Step 1

Open the configuration folder for codestyles:

macOS

  • ~/Library/Application Support/Google/AndroidStudioXXXX.X/codestyles

Windows

  • %AppData%\Google\AndroidStudioXXXX.X\codestyles or
  • %AppData%\Roaming\Google\AndroidStudioXXXX.X\codestyles

Linux
currently unknown sorry

Step 2

Add a new section into the file your IDE is using. Mine is codestyles/Default.xml.

Like this:

<code_scheme name="Default" version="173">
  ...
  <codeStyleSettings language="Dart">
    <option name="BRACE_STYLE" value="2" />
    <option name="METHOD_BRACE_STYLE" value="2" />
    <option name="ELSE_ON_NEW_LINE" value="true" />
    <indentOptions>
      <option name="INDENT_SIZE" value="4" />
      <option name="TAB_SIZE" value="4" />
    </indentOptions>
  </codeStyleSettings>
  ...
</code_scheme>

Upvotes: 6

Vaibhav Aggarwal
Vaibhav Aggarwal

Reputation: 61

If you are an Android Developer and cannot leave Android Studio, since it's your coding home, but can't let go of flutter either.

Use a different theme: Visual Studio 2019 Dark Theme (this auto adjusts indentation and makes code look exactly as of Visual Studio Code). To install theme - plugins -> search "Visual Studio 2019 Dark Theme"

OR

Use a different font: I prefer

Font : "Droid Sans Mono Slashed" or "Monospaced" (You can use any that works for spacing)

Font size: 18 , Line Height 1.4 // For 14 inch screens

Font size: 14 , Line Height 1.2 // For 15.6 inch screens or larger

enter image description here

OR

A combination of above looks beautiful.

enter image description here

Upvotes: 0

Andrew Penhorwood
Andrew Penhorwood

Reputation: 33

Android Studio 2020.3 %AppData%\Roaming\Google\AndroidStudio2020.3\codestyles

Default.xml

I found the codestyles at the above location on a Windows 10 box. Find the Dart section of the file. Add the tab options you want.

  <codeStyleSettings language="Dart">
    <option name="RIGHT_MARGIN" value="1000" />
    <indentOptions>
      <option name="USE_TAB_CHARACTER" value="true" />
      <option name="INDENT_SIZE" value="4" />
      <option name="TAB_SIZE" value="4" />
    </indentOptions>
  </codeStyleSettings>

Upvotes: 2

Mike N
Mike N

Reputation: 508

Remark for Android Studio 4: In Android Studio 3.6 and below, dartfmt could simply be disabled, as described by Astavie. Unfortunately, this function has been removed in Android Studio 4.

Upvotes: 1

Astavie
Astavie

Reputation: 101

I needed to disable Dartfmt under Settings -> Editor -> Code Style -> Dart

Upvotes: 0

Related Questions