Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Code Style in Intellij Idea / Android Studio

Tags:

Before Android Studio, I was using android-formatting.xml as Code Style in Eclipse.

How can I setup Android Studio / Intellij Idea to format code as in Eclipse?

UPDATE

I tried Eclipse Code Formatter plugin. It seems to work, but you cannot edit any setting at all. My team prefers 120 columns instead of 100.

I tried @CrossleSong answer too. It's a bit tricky, but more powerful. You can save this

https://android.googlesource.com/platform/development/+/android-4.2.2_r1.2/ide/intellij/codestyles/AndroidStyle.xml

as Android.xml and copy it to AndroidStudio/Intellij codestyles folder: for me is

~/Library/Preferences/AndroidStudioPreview/codestyles

Now you can select Android as Code Style in Android Studio Preferences.

like image 882
Ivan Morgillo Avatar asked May 23 '13 09:05

Ivan Morgillo


People also ask

How do I add code style to IntelliJ?

Apply a predefined code stylePress Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. To configure a scheme for new projects, go to File | New Projects Setup | Settings/Preferences for New Projects | Editor | Code Style. Select the language for which you want to configure the code style.

How do I fix code style in IntelliJ?

In the editor, select a code fragment you want to reformat. Before reformatting, you can take a look at the code style settings that are applied to the selected code: press Alt+Enter and click Adjust code style settings. From the main menu, select Code | Reformat Code or press Ctrl+Alt+L .

How can I beautify code in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.

Can I use IntelliJ IDEA for Android Studio?

Android Studio and the Android plugin for IntelliJ IDEA are built from the same code, and all of the changes in Android Studio are, and will continue to be, available in IntelliJ IDEA releases.


2 Answers

You can download the development repo from Android source. The development/ide/intellij folder includes code style, templates...

like image 102
Crossle Song Avatar answered Oct 16 '22 17:10

Crossle Song


Instructions to use Eclipse XML formatter in Android Studio:

  1. File -> Settings -> Plugins
  2. click 'Browse repositories' button, enter 'Eclipse Code Formatter' in the search field and install the plugin.
  3. Restart Android Studio.
  4. File -> Settings -> Other Settings -> Eclipse Code Formatter (if you cannot find it, then use search field for that)
  5. select 'Use the Eclipse code formatter', browse your xml style file and press OK button to close the Settings.

I hope I wrote instructions clear. Let me know in case you didn't understand.

like image 27
Ayaz Alifov Avatar answered Oct 16 '22 17:10

Ayaz Alifov