Android Studio saving custom code templates - android

I couldn't find where exaclty in the android studio you can save custom codes for example if i want to save:
Toast.makeText(getApplicationContext(), "Message.",Toast.LENGTH_SHORT).show();
If i wanted to save the code and make a shortcut for it for example toastMT
how do i do that exacly?

Goto Preferences
Select Editor on the left pane
Select Live Templates on the left pane
Here you can find a list of predefined templates and you can add your custom ones. If you want to use your template, simply start typing, e.g. toastMT and Android Studio will provide a suggestion to use your template.

Related

How can I add custom wrapper like keyword 'sout' - system.out.println in android studio?

You know about this special quick wrapper, if you select sout, it will wrap System.out.println() around whatever your cursor is at.
I use lots of log.d, log.wtf, is it possible to write my own command like:
'ltf' and it appears in the pop-up window above?
They are called "Live Templates" in AS. Go to Preferences in AS and type there "live" or navigate to Editor - Live Templates. There is a button with "plus" icon on it in the top right corner. Press it to add a new template.
Some Android logger templates are already there, like logd, loge etc. They are expanded by "Tab" key by default.

Code for "simple_list_item_2"?

Been working on an android application with a custom listview. I recently had to change to a cursor to accomplish what I wanted to do.
As a result, I ended up making use of android.R.layout.simple_list_item_2 because it worked how I wanted. Problem is that I would like to change a few properties such as font color and edit my cell as I see fit.
Question is, Can I find the code for simple_list_item_2 somewhere and edit it as my own, and call it instead of simple_list_item_2?
easy to get it. If you use Android Studio, you can put your cursor on android.R.layout.simple_list_item_2 and press Ctrl + B or F4 to get it.
if I don't make a mistake, F4 similar to F3 on Eclipse!
UPDATE 1
on Android Studio, you also get it by right click on it and Go To >> Declaration
UPDATE 2
on Android Studio, you also get it by hold controll and click on simple_list_item_2.
If you use Android Studio on MacOS, let hold CMD instead
You can find the code for this component by searching for simple_list_item_2.xml in the Android Open Source Project's frameworks. For example, it's available here in the GitHub mirror of the official repository.

Android Studio live template not working

I've created a Live Template under the "user" template group. I've set the Abbreviation to "setpref". It is listed on my list of Live Templates, but it is not available when I type "setpref" in a code window. I'm guessing that I've missed something obvious but can't work out what.
Any ideas??
To make the Live Templates appear again, do the following:
1) Open Editor>Live Templates
2) When you find templates with issues, select them and do step 4-6
3) At the bottom, click Change where it says "Applicable in..."
4) In the popup, under Java select statement to make templates like logd, logm, logw etc be available inside methods.
5) Select declaration to make templates like logt available in classes' field declarations.
Done!
Visit this link - https://www.reddit.com/r/androiddev/comments/3n9nis/issues_with_live_templates_in_android_studio_try/?st=j0pjkc4w&sh=e84eb254
Have fun ! :) It works.
Please make sure that you've correctly specified the context for your live template (the set of languages in which it's available).
If you see below the editor of live templates this sentence.
No applicable contexts.
click on "Define" beside the text.
select the language you coding.
Ok.
If you are using Kotlin:
Open the "Preferences" menu item
Search "Live Templates"
Put your template below Kotlin set

Android Studio Multi-Windows for One Project

I'm wondering if anyone knows how to open two windows of Android Studio with both having the same project. I know you can drag tabs out, but that allows you to only edit that one file. I want two fully-featured windows with each being able to see the Project Files/Structure.
I don't want to just split the editor, I want a separate window.
I want two of these windows, with both "looking" at the same project:
I don't want another one of these windows, as I can't view the project structure and change that, and it's hard to change it to a different file in this view:
Right click on tab of the file and click "Split vertical / Horizontal"
After splitting, you can just drag one of the tab titles to the second monitor - it will open up a new window. You can then edit the same file in two separate windows
If you click and drag a file's tab out of your current window (over onto the desktop, for example), the file will open in a new window. However, this window doesn't seem to have the whole package explorer, console etc.
Although, if you click on the gear on any of the modules, you can uncheck 'pinned' mode and you'll be free to move them around your two monitors just like the window you created above.
Window -> Editor Tabs -> Split Vertically
if you don't use files tabs
If you want to split tabs of android studio project beetween monitors, you can rigthclick to tab(project, debug, terminal etc) and check the "floating mode" option.
See the image: Floating mode tab option
After that you can drag this tab between your monitors as new window.
Could you just make a copy of android studio & run it side / side? You can run different versions of android studio side/side.. Maybe that is an option.
Just drag the tab outside the current window.
right click on tab and click on windowed mode, it will open up a new window.
One hacky way of doing this (but you will not be able to save in the same project) is to make a copy of the project folder and open it in Android Studio.

Android Studio seeing which files a change was applied to

I was doing a code inspection with Android Studio and I accepted a change across multiple file which I now wish to undo.
When I go to VCS|Local History | Show History for one of the files, I can see the change was applied to 25 files, but I do not know how to show which files these are. I have version 0.3.5
Right click on your project in project structure on the left. then Local History -> Show History. If you want to show history only for src folder, click on it.. the same for layout folder etc..
You can use Shelve changes.
This is a great tool to view your changes.
Here is how to open the 'Shelve changes' dialog in Android Studio :
And here is what the dialog looks like :
You can also use this box to commit your changes if you want.

Categories

Resources