Everytime I create a new project in Android Studio, by default I get in my MainActivity, a TextView containing "Hello World", which every single time I need to remove it. Why that? Is there any option that can allow me to create a new project witout it? Thanks!
Everytime I create a new project in Android Studio, by default I get in my MainActivity, a TextView containing "Hello World",
That is because of the specific choices that you made in the new-project wizard. You chose to create an activity, and you chose an activity template that has that particular content.
Is there any option that can allow me to create a new project witout it?
Opt not to create an activity when you create the new project. In other words, in this screen, choose "Add No Activity":
Related
I have a project with a lot of classes in which I need to change the Created by template.
/**
* Created by johnnyfivedev on 19.07.16.
*/
Since there are a lot of such classes, copy and paste not an option. Rather I want to remove that generated template and regenerate it. Is there any default shortcut for doing this? If not, then how do I create one?
Rather I want to remove that generated template and regenerate it.
You can surely edit the template but you can't regenerate it again. I suggest editing the template for your future uses and creating a live template for those made prior to this template change.
Editing the template
Go to Settings -> Editor -> File and Code Templates -> Includes -> File Header
and override the ${USER} function like so:
#set( $USER = "Your name")
If you want, you can add a lot more variables to it.
NOTE: These changes will only take effect on new files. The ones made prior to this template change will have to be manually changed.
Press Ctrl+Alt+S to go directly to the File and Code Templates tab.
Creating the live template
Go to Settings -> Editor -> Live Templates
Press the green 'plus' sign to add a new template, and select Live Template.
In the abbreviation field, type what you want to, I typed annot, add a suitable description (optional) and insert the following code in the box:
/**
* Created by $USER$ on $DATE$.
*/
$END$
Select the Edit variables box and write the following expressions in the corresponding fields,
user() for USER
date("dd-MM-yyyy") for DATE
After that type define applicable contexts as you see fit. In your code, now type annot and press Enter to insert the template.
In the code, your cursor will end up at the place of $END$ upon pressing Enter after template insertion.
you can change your code generation template in settings of the android studio where you can change what name appears and date.
Here is a snapshot of where it is.
but this won't work for your existing files where you can change manually.
When you create new activity using IDE constructor (new->activity) - in both Android Studio and Eclipse - it creates new java file, layout file, adds activity to the manifest etc.
And every time there's a TextView with "Hello World" text at the layout file (if you choose "Blank Activity" pattern). Also string value "Hello World" is automatically added into strings res file.
Of course no special effort is needed to delete manually string value and TextView but one day it becomes really annoying.
My question:
If there's a way to change the new activity creation mechanism and create just empty activity layout file (only with container layout, e.g. RelativeLayout)?
you can go to your sdk path
/sdk/platforms/[android-version]/templates
and modify the template files
Go to your SDK Path. In my case
sdk\platforms\android-[version]\templates
And open layout.template in any editor like Notepad++
Delete Textview widget from this layout.template file.
I got it
layout.template file should be modified.
Path is: Android Studio\plugins\android\lib\templates\activities\[Activity-Type]\root\res\layout
Is there a way to generate my out shortcuts, like sout or soutv and so on, in Android Studio ? I'd like to make something like mab and then press ctrl+spaced which will generate a predefined method and then let me fill out the params for it. (so basically the same as sout)
Yes you can, they're called Live Templates,
here is an example of someone doing it
https://github.com/manhluong/peng/blob/master/PengAndroid/src/com/luongbui/peng/android/InstallWatchAppTask.java#L50
Here is the IntelliJ docs
https://www.jetbrains.com/idea/help/live-templates.html
To create a new template from scratch
In the Settings dialog, open the Live Templates page, and expand the
template group where you want to create a new template.
Click add (+).
A new template item is added to the group and the focus moves to the
Template Text area.
Specify the new template abbreviation, type the
template body, define the variables and the template group, configure
the options, as described in the template modification procedure.
Click OK when ready.
Till Eclipse, creating a second activity and class had a brevity . However, with the new official Android studio , I feel more of an abstraction . Earlier, while creating an activity it specified many things, nevertheless asked the layout of an XML file. And here are my doubts:
1) Is there an option to create Java file in Android Studio just like we use to do with Eclipse ?
2) Which is the best way to create an activity in Android Studio with our specified layout?
1) You can go into the project directory and right click the folder where you want the activity to be (typically in src/java/com.xxx.xxx/) and select New -> JavaClass and create YourActivity and make sure that YourActivity extends Activity. Be sure to add the activity to your manifest!
2) There is no best way as it is a matter of preference. Personally I do what I said in step 1 and create the xml layout file myself in the res folder. I find that Android Studios auto activity creation to be a bit annoying as they add menu xml files that I do not need.
I added a Test project to my main project like it's shown here.
However, when I try to right click and go New -> Class to add a test class, the src folder is set to my main projects source folder, and the package is set to my main projects' package, and the test/ folder doesn't show up when I click on browse.
How do I set the test directory up properly, in Eclipse?
When you click on new class, you get the popup window, where you can set the new package name. (If you're not looking for this, then you should try out new thing below).
You can click on the package(which was created when you made new project), right click that package, then go new and new class to set up properly.
I hope this answer's your question.