Using tab identation instead of spaces on Android Studio - android-studio

Just trying to use tab-indentation on Android Studio 2.2.2
I followed the instructions I found on this thread:
Android Studio "This file is indented with tabs instead of 4 spaces"
But these instructions work only for new documents I create after setting that configuration but for previously created documents the space-indentation persists.
How can I configure all the files on my project to tab-indentation? for files before and after the tab-indentation configuration on the link above?

After changing the settings you have to reformat your codes, you can do this one by one by opening the file and pressing (Command + Option + L) shortcut or right click on your src folder and selecting Reformat Code option:
You can check the result by selecting View -> Active Editor -> Show Whitespaces from the menu:
which would be something like this:

Related

Android Studio isn't showing the xml editor [duplicate]

How can I enable the text/design Tab on the a src/main/res/layout folder on the activity_main.xml file that was created automatically during create new project? If i do right click and create xml file on the said folder, the design/text tab exist. Any suggestion? Thanks.
No Text/Design Tab on the Bottom Part of the Android Studio
Creating a new XML in the Res/Layout Folder, the design/text tab is now present.
Any help? this is super weird guys...
In Android Studio 3.6 use these three buttons (Code | Split | Design), on top right, to switch between views.
I had the same problem, restarting the IDE did make that tab appear again.
On Android Studio 3.6.1
Top Right corner under the main toolbar you have three different icons (Code, Split, Design).
View -> Tool windows -> Preview .
Output view:
use the three buttons (Code|Split|Design)on top right hand side to switch between views.
I also had this problem after upgrading to 1.5. None of the above suggestions worked for me. I noticed that the default relative layout xml has changed with a third xmlns line and an app behavior line. I opened an older project and copied the old relative layout header to replace the new. Instantly the preview function was restored.
You can also Move between Design / Text tabs in layout’s view with simple shortcut:
(Mac) : control + shift + ← / →
(Windows / Linux): alt + shift + ← / →
On the top right corner of the activity_main.xml file view, there are 3 icons representing "Code", "Split" and "Design". Click on the leftmost icon of the three ("Code") for the text tab.
In the android Studio window, at the left side there are two options available(Project and Resource Manager). Go to resource and there you will see an ADD Module option, click on that. After this you will see your text and design option will get enabled, you can go to your work area by Project Name->app ->src ->main->res ->layout.
Yes, Even I had the same problem. For the first time... I think It wont show, restarting the IDE did make that tab appear again.
I had this problem too, I deleted all the preference files, such as the AndroidStudioPreview folder & com.google.android.studio.plist, then restarted android studio, it worked.
You do not need to restart an IDE. All you need is to close an xml file that does not get a tab and reopen it within an editor. It is a little bug.
Navigate to activity_main.xml tab then Design and Text tab appears.
It doesn't appear in MainActivity.java tab.
You do not need to restart IDE.
If text/design tab is missing in new android studio, this can solve by two methods.
You have re-install android studio. And don't forget to delete android studio related all files from temp and local.
Or you can re-install SDK (software development kit) according to your device.

"Keep Tabs" setting not working in Visual Studio 2019

I've been having a problem in Visual Studio 2019 where the program enters tabs as four spaces. This is annoying, since I have to hit backspace 4 times to erase an indent, and I need to use arrow keys 4 times to navigate an indent.
This used to work fine, but I had to uninstall and re-install Visual Studio to fix another problem (it kept running old versions of my code and wouldn't run the new version), and ever since then, I haven't been able to get it to work.
I went to settings, and selected 'keep tabs', but it still replaces it with four spaces every time i hit the Tab button. Interestingly, when I start a new line, I can navigate and backspace normally, but if I enter any more tabs, they are replaced with 4 spaces.
I've tried looking around, but I can't seem to find anything that addresses my issue. Can anyone help?
How to fix problem in Visual Studio with "Keep tabs" not working.
I also had this problem with tabs being converted to spaces.
I checked Tools>Options>Text Editor> (All languasges as well as c/c++) >Tabs> and assured that "Keep tabs" was selected.
After some trouble shooting I found that only one file had this problem (file1.h).
I created a new empty file (file2.h) that worked correctly.
I took the statements from file1.h and divided them into small block. Then I moved the blocks to file2 and after each block I tested file2.
After a few block suddenly file2.h failed. When I removed the last block from file2 the problem was solved.
My conclusion is, that the source code contained some invivisible code, that made the text editor turn off the "Keep tabs" setting.
I have seen comments about a setting "Use adaptive formatting" that might be relevant. So far I have turned this setting off.
My setup is Visual Studio Community 2019 v 16.4.4 with an Arduino plug in from Visual Micro v 1912 28 2.
/Steen
Disable the checkbox: Tools->Options->Text Editor->Advanced->Use Adaptive Formatting
You will still need to delete the spaces it inserted for you, but will retain tabs afterwards.
Also note that Visual Studio 2019 now uses and prioritizes .editorconfig files over the Tools -> Options -> Text Editor settings.
If you have tried the above answers and still cannot get your indent and tab settings to work, then look for an .editorconfig file anywhere in your project's directory structure.
For instance in my project Angular CLI created one for me when I initialize a new ng project in my .net Web API directory structure. All my *.ts files were not cooperating.
I had to edit the .editorconfig file to look like this in order to get 4 space indent and tab instead of spaces. Once I did that, Ctrl + K + D (reformat) started working again:
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.ts]
quote_type = single
[*.md]
max_line_length = off
trim_trailing_whitespace = false

difference between Reformat Code / Reformat Code with dartfmt

In Android studio, when I open a dart file, I see two options to format the code, so my question is
What is the difference between Reformat Code / Reformat Code with dartfmt
Difference between them I don't know but I know how you can add a shortcut to format code:
Go to
File -> Settings -> Keymap -> Editor Action -> Reformate Code with dartfmt
and add click on it and add a shortcut
Both are the same essentially.
The only difference is that Reformat Code (ctrl + alt + L) applies only to the file open in the Editor or the file selected in project files pane using Intellij's Code formatter feature.
While Reformat Code using dartfmt uses dartfmt CLI command available with the flutter SDK.
The output of both will be the same. dartfmt allow you to format the code on directory level and from a cmd/terminal instead of an IDE.
**Automatically formatting code in Android Studio and IntelliJ
**
Install the Dart plugin to get automatic formatting of code in Android Studio and IntelliJ.
To automatically format the code in the current source code window, right-click in the code window and select Reformat Code with dartfmt. You can add a keyboard shortcut to this in Keymap section of IntelliJ Preferences.
You can also do it with
flutter format path1 path2 ...
(From terminal window)
Official link to flutter formatting tool
This shows that dartfmt is just a formatter by dart specifically for dart files. Default format code given by Android studio also could do this if file extension is identified by Android studio.

Is there a way to use Sublime to show file previews in Windows Explorer for certain files?

I'd like to be able to preview all plain-text files in the Windows File Explorer Preview Pane. To illustrate, here's what sublime files currently look like:
As you can see, Context.sublime-menu is highlighted, but a preview doesn't appear. They're just plain-text files though - you can open them in Notepad. Is there a way to tell windows "Use notepad (or sublime) to view this type of file the preview pane"?
Thanks to #KeithHall's link - while it didn't work for me - got me started on a pretty long path to finally figuring this out. And finding a better solution than I thought existed.
In short, simply install the Delphi Preview Handler. Which pretty much gives you an IDE in the preview pane. It's pretty simple to use and just awesome.
After installation, if you click on a .js file in Windows File Explorer you can immediately see a different preview pane.
Registering Other Extensions
The Preview Handler doesn't compensate for all plain-text files unfortunately, so you're gonna have to manually add the sublime extensions and any other extensions in the Registry Editor.
Here's the bird's-eye view of this process:
Find the key/value that instructs Windows to use Delphi as the preview handler for .js files.
Copy the key/value
Apply that to each extension you want to preview.
Here's more in-depth instructions:
First, you need to find the ID of the Preview Handler, and its Default Value
win + rregedit > expand HKEY_CLASSES_ROOT
Find .js and expand it.
.js should have a subkey named shellex, expand that
You need to recreate this shellex key for each extension you want to add, so copy its contents:
shellex should have a sub-key named with a bunch of numbers, letters, and dashes, this is the ID of the preview pane (I think)
Right-Click that > Rename > Copy > Cancel
Open Sublime > Create a new file > Paste
Go back to the Registry Editor, Click that ID subkey, and a String value called (Default) should appear in the right side of the window.
Double-Click that
Copy > Cancel > Paste in sublime. This is the ID of the Preview Handler (I think).
At this point there should be 2 IDs in the sublime file.
Now You're ready to add these same values to other extensions.
Find the extension(s) you want to change. For me it was all the sublime file-types.
Right-click > New > Key > call it shellex
Go to sublime, copy the first value
Right-click shellex > New > Key > Paste
Go to sublime, copy the second value
Click the new key and make it's default value that 2nd id.
So it should look similar to this:
v .sublime-commands
| v shellex
| |- {823BD1D4-...
And in the right side of the window:
Name Type Data
(Default) REG_SZ {AD9955...
Sources:
This Answer by #rxantos pointed me in the direction of the Delphi Preview Handler.
I spent about an hour looking for this app but never found it.
This Answer by #tvj247 is perhaps a more simple solution, but my HKey structure didn't match his (I'm using Windows 10).
And as for fiddling with the Registry, that was trial, error, and comparing sublime extension keys to js, html and css.

shortcut in Android Studio to locate the current editing src file

Do you know how to check the location of current editing file in the project tree panel (the very left panel of the Android Studio), except manually. (The worst case is that all the folders there are collapsed)
The Navigate->Class shortcut can show me the src file in edit panel (central panel) quickly. Then I want to know the src file's logic location in project tree (left panel), so that I can add some new files in the same package quickly. (e.g. right-click the package and add new Class).
Currently, I have to expand the project tree and find it folder by folder.
Actually, in Xcode there is such a shortcut named "Reveal in Project Navigate"
What a convenient way it is.
I wonder whether this is also supported in Android studio.
Thanks
You can use the Scroll from Source button in the Project Toolbar in the left of Android Studio.
Another solution is Alt+F1+1. You can also read Locate current file in IntelliJ for more answers.
Just enable the following option!
In Android Studio 4 it is now Always Select Opened File under the Settings menu in the project view.
For automatic scrolling, you can do following:
You need to ensure Autoscroll to Source and Autoscroll from source is enabled.
Whenever you change the file the Project tree will be highlighted according.
I have observed some slowness and lag if project size is big(several modules or huge code base) and you use short cut Ctrl + N to navigate to a class.
So the alternative would be to either to click following icon:
OR
Use keyboard shortcut:
Alt + F1 + 1 or Alt + F1 + Enter
You can add shortcut (keymap) to "reveal current editing file in project explorer" command.
Press Ctrl + Alt + S, for Windows user, to open Settings
Select Keymap on the sidebar
Find the command using search box, type this into it: select in project view
Right click the result then select Add Keyboard Shortcut
Type any keyboard combination you want, for example, me prefer shortcut Ctrl + K to reveal current editing file on project explorer
Click OK button. It will prompt you to remove keyboard shortcut you typed from existing command, so just click Remove button.
I'm new to android development. I used to code in Sublime Text 3. One of first thing I do to make android development feels more enjoyable is binding all shortcut I used in Sublime Text 3 to Android Studio. Now, it feels like home :)
For Mac users: Option+fn+F1, then Enter.
Android Studio 3.6.3 (April 2020)
Go to Preferences > Keymap & search for "Select in Project View" and assign your keyboard shortcut.
Under options menu, select Auto scroll from Source
Navigate -> Select In.. -> Project View -> Project
open pref -> Keymap, then search 'select file in project view', not 'select opened file'.

Resources