Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 562
Astavie Avatar asked Oct 15 '25 04:10

Astavie


1 Answers

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>
like image 113
iOSonntag Avatar answered Oct 16 '25 21:10

iOSonntag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!