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
Related
When i started new project in android studio with tab layout activity instead of blank activity i tried to add a new activity along with main activity normally we get xml file added automatically when we add new Kotlin class, but here I am not getting new xml file added please let me know what we can do.
If you want to create a new XML file, you can right click on the layout directory, and choose new layout file because in the newer versions of android studio, it no longer auto generate XML file.
I study a course and it told me to edit this layout file, How can I find it please because I searched on it and I did not find it
The course instructor told me:
""
In the new versions of Android Studio, after choosing the Empty Activity template, the layout file app/src/main/res/layout/activity_main.xml will look like this:
""
You must have created this file when you first created the project and this must be your launcher file. Navigate through your project and you can easily find your file.
To search, press Shift + Shift i.e. press Shift 2 times and type your file name and it will show you the results.
You can find this file under the layout folder in this menu:
I want to delete the entire "General" section in the settings, but I do not know how to safely do so. I'm afraid there will be errors in the SettingsActivity.java file that I have.
To clarify: In my new android studio project, I am using a pre-made settings activity, and the activity has several pre-set preferences. I want to delete the pref_general.xml preference because I don't need it but I'm not sure if just deleting the .xml file will be enough or error-free. Hope this helps.
you can delete it but in Preferences Activity you must delete this class:
and properly remove this line (line №1):
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 am using eclipse IDE. If I have a variable or an instance of a class. If I select it and do Ctrl+Shift+G, I can get all the references to that variable or the class instance in that workspace. Similarly, can I get references to an xml file in the android code using any short cut?
Lets say, I have layout xml file app_view.xml. I need to search the android code where this xml is being referenced.
I don't know of any shortcut, but you could just use the search menu to search in your project for occurrences of
R.layout.your_layout_name
If you copy (ctrl + c) in a java file the text R.layout.your_layout_name, you can directly use Search => Text => Project.
Or a less 'elegant' solution, temporary remove the xml from the project, so that you can look for compile errors in your java sources.