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
Related
When editing Java files, if I'm at the end of the line and I type the Enter key, it starts the next line properly indented 4 columns, to match the line above. That's OK but it's indenting with a tab, not spaces, even though in File>Settings>Editor>Java>Tabs and Indents the checkbox for Use tab character is unchecked, and always has been.
If I just type the tab key I also get a tab, not spaces.
I never want to use tab characters; I always want to use spaces. I don't have this problem in Eclipse or Microsoft Visual Studio so it's not some system setting for my PC. Is there some other setting in Android Studio for this?
Edit: I tried the suggestion that Omar Al Halabi (below) made and it didn't work but while testing it I noticed something interesting: This tab problem seems to mainly apply to the beginning of the line, i.e., if I type Enter on the previous line, it immediately tabs over to the first indent position on the following line, using real tabs, not spaces. On the other hand if I'm typing some text on an existing line, once I've typed a little text, if I hit tab, it then tabs over using spaces.
hope this helps,
check Use Tab Character,
give all that values to zero than you not get space on enter in java code, like in below image,
one more thing is you have to change your code format settings or may need to disable it
This is not an answer, but I don't have enough reputation points to post my questions as a comment.
- Is this issue happening in all your Android Studio projects?
- Are you using the Default scheme for the general File->Settings->Editor->Code Style and also for the Java Code Style?
- Have you tried making a new Java Code Style scheme at the Project level for just one project as a test?
EDIT: This is a brute-force/shotgun approach.
Rename your \Users\<username>\.AndroidStudio2.1 directory (e.g., .AndroidStudio2.1_orig)
Open Android Studio and force it to use the default settings by choosing the "I do not have a previous version of Studio or I do not want to import my settings" option when the "Complete Installation" dialog window appears.
Run a recursive 'diff' between the new and old .AndroidStudio2.1 directories to find any changes you've made to the default settings so you can re-apply them. The settings are kept in XML files so they are human-readable. Keep an eye out for any differences that may affect Android Studio use of tabs & spaces, because those might be the source of the problem.
If this does not work, then you may have to re-install Android Studio.
Try opening Settings->Editor->Code Style->Java. Check "Use tab character". Click OK.
Then go to File->Invalidate Caches\Restart -> Invalidate and Restart.
Then, again, go to Settings->Editor->Code Style->Java. Now uncheck "Use tab character" and hit OK.
If it still doesn't work change tab size and indent and then restore them back if you want.
The IDE tries to position the lines as if they belong to the same block. Also very likely you had used the tabs on the previous line. You can try to deactivate Detect and use Existing file indents for editing
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.
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.
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.
I program android apps and i have one annoying feature in eclipse that i don't know how to turn off. I want eclipse to auto fill android:textStyle and give me more options like "bold", "italic" and not auto fill android:textStyle="" without giving me option to choose like mentioned above. Please be specific and repply ASVP. Please give me instructions like go to file->open... and i have eclipse 4.2.1 with ADT Version: 20.0.3.v201208082019-427395 THANKS
The auto fill you are describing is called Content Assist. You don't need to change the way it works, you simply need to learn more about it: You can trigger this method manually by pressing Ctrl+Space at any time.
On a new line in your View's XML type: textst and press Ctrl+Space to get:
android:textStyle=""
While the cursor is still between the quote marks press Ctrl+Space again to see the list of "normal", "bold", "italic".
Also you can quickly add more styles by using | symbol, for example android:textStyle="bold|", simply press Ctrl+Space to another say "italic"...
android:textStyle="bold|italic"
Added from comments
I don't know much about customizing Content Assist, but to reach its XML settings go to:
Window -> Preferences and then XML -> XML Files -> Editor -> Content Assist
You can find various settings here, including choosing the delay and prompt characters. If you use <a:="| this will cover the beginning of almost every line in an Android XML file. But you might want to be comprehensive by listing every character aAbBcC (etc) to open the Content Assist as much as possible...
Also you can make keyboard buttons with the HTML keyboard tag, for instance I made Bonzai! with:
<kbd>Bonzai!</kbd>