<Android Studio> Android Studio 配置Code Style

来源:互联网 发布:ubuntu进不了图形界面 编辑:程序博客网 时间:2024/05/22 10:31

步骤一:下载

下载Square的代码规范

git clone https://github.com/square/java-code-styles.git

步骤二:安装

windows install.bat Macos/Linux install.sh

看下脚本内容:
install.bat

REM Installs Square's IntelliJ configs into your user configs.@echo offecho Installing Square IntelliJ configs...setlocal enableDelayedExpansionfor /D %%i in ("%userprofile%"\.AndroidStudio*) do call :copy_config "%%i"for /D %%i in ("%userprofile%"\.IdeaIC*) do call :copy_config "%%i"for /D %%i in ("%userprofile%"\.IntelliJIdea*) do call :copy_config "%%i"echo.echo Restart IntelliJ and/or AndroidStudio, go to preferences, and apply 'Square' or 'SquareAndroid'.exit /bREM sub function for copy config files:copy_configset config_dir=%~1\configecho Installing to "!config_dir!"xcopy /s configs "!config_dir!"echo Done.echo.exit /b

install.sh

#!/bin/bash# Installs Square's IntelliJ configs into your user configs.echo "Installing Square IntelliJ configs..."CONFIGS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/configs"for i in $HOME/Library/Preferences/IntelliJIdea*  \         $HOME/Library/Preferences/IdeaIC*        \         $HOME/Library/Preferences/AndroidStudio* \         $HOME/.IntelliJIdea*/config              \         $HOME/.IdeaIC*/config                    \         $HOME/.AndroidStudio*/configdo  if [[ -d $i ]]; then    # Install codestyles    mkdir -p $i/codestyles    cp -frv "$CONFIGS/codestyles"/* $i/codestyles    # Install inspections    mkdir -p $i/inspection    cp -frv "$CONFIGS/inspection"/* $i/inspection    # Install options ("Exclude from Import and Completion")    mkdir -p $i/options    cp -frv "$CONFIGS/options"/* $i/options  fidoneecho "Done."echo ""echo "Restart IntelliJ and/or AndroidStudio, go to preferences, and apply 'Square' or 'SquareAndroid'."

从代码上看,和手动配置一样,但是脚本的执行效率事不言而喻的。
执行完成之后大致就是如下log:
这里写图片描述

步骤三:配置

Preference > CodeStyle > Java

这里写图片描述

and then you can choose what you like ~ over!

1 0