Easy way to include third-party Views in Android Studio? - android-studio

When working with ExoPlayer in Android Studio, to add a PlayerView to my application's layout I always have to click on the "Text" tab and dive into the XML.
Is there a way to add such third-party views to the palette so I can drag and drop a PlayerView directly onto my layout?
Update
Here's a screenshot of my Android Studio IDE. There's no "Project" tab or other clear means of adding to the palette

Palette has "Project" tab, hope this helps

I believe I may have figured out the source of my issue. As I mentioned in the original question, I'm working with ExoPlayer.
First, a View will only show up in the design palette if it's defined either in your project or in a JAR file
Next, ExoPlayer does not distribute a JAR file
When using jcenter to pull in ExoPlayer (as instructed by their installation guide) it will not build a JAR and so Android Studio is unaware of any custom views

Related

Create a layout inspector *.li file with Android Studio 4.0

In Android Studio 3.x (and before) when I ran the Layout inspector, the view hierarchy was automatically captured and saved in a *.li file. When I start the Layout Inspector in Android Studio 4.0, the view hierarchy is not saved anywhere.
Can I somehow export the view hierarchy from the new Layout Inspector to a file, so I am able to share it with others? For now I can say that I'm only able to open the *.li files in AS 4.0, but not save it.
I found one solution for the above case. You need to type shift two times and then type legacy layout inspector. The old layout inspector will open and you can save its .li file.
I found it useful because I can do it in the Android Studio 4.0.
I can use new feature from Android Studio 4.0 Layout Inspector as well can save .li file using the legacy layout inspector.
Another option is to disable the Live Layout Inspector feature in the Android Studio Preferences window. It can be found in the Experimental section, as in the screenshot below:

Show all drawable content in Android Studio

In my project I have got a lot of drawable content, and when I need to add new images to drawable I can put a same resource because I forget I have it already.
It is not about preview on XML file, this works well.
Any features in Android Studio to preview all my drawable contents without double-click on every resource? It can save lots of time.
I didn't find anything at Preferences, maybe some plugin or did I miss something?
Starting from Android Studio 3.4, you can use Resource Manager, a new tool window for importing, creating, managing, and applying resources to your app's layouts. You can open the tool window by selecting
View > Tool Windows > Resource Manager from the menu bar.
Right click on drawable folder and click 'Show Image Thumbnails'.
I'm using Android Drawable Viewer that can be installed from Plugins in AndroidStudio. After installing and restarting Android Studio, you will find a tab on the right side of the editor where you can find the viewer.
Click on that tab and you'll be asked to select the root folder for drawables. Do it, and after, everything will look like this:
Consider using Android Drawable Preview plugin. It shows content of the images instead of default icons when you expand drawables.
It even renders vector xml drawables!
Like this:
To install it: go to File > Settings > Plugins > search for Android Drawable Preview and click to find in repos. Install it and restart Android Studio.
Cheers!
Note/ when using 'Show Image Thumbnails' (as #Akhil Tawari suggested) in "Android" view as opposed to "Project" view, for image thumbnails of all drawables right click the "res" folder and not the drawables folder/s.
You can right click on the folder and click open in files. This will allow you to open up the project folder in which you can more easily add and delete images and other files.

Can't add a new activity on android studio

I'm trying to improve my android development skills, so working on some project about it. In my project, I added a new "Navigation Drawer Activity", then I deleted it because I wanted to create a new one but I can not able to add even another type of activitiy. Android studio adds ,
<activity
android:name=".ExampleActivity"
android:label="#string/title_activity_main" >
</activity>
tag in AndroidManifest.xml but It doesn't create any classes and xml layout files.
Also studio says:
ide internal error occurred android studio.
I tried regenerate R.java and clean my project ,but it doesn't work. How can I get rid of this problem?
Try to add a simple JavaClass and write an "extends Activity" behind the class name. And put this new Activity in the Manifest like in your example. You can add a menu and a layout like this, too, when you add xml-Files in the layout and menu folders. This should work.
I can not find a exact solution to that problem. Re-installed the Android Studio . It does the solution manually
If it's about how Activities is not showing up as an option in either the shortcut menu in the Layout folder or File + New in the menu, you can try File + "Sync Project with Gradle files" and give it some time.
This also adds options to the Tools menu (great if AVD or SDK Manager is missing).

How do you save multiple tool window layouts in Android Studio?

I arranged my Android Studio IDE tool windows layout to fit 2 screens in a dual monitor setup and saved it as the default. I would also like to save another layout for single screen setup.
Question: Is it possible to save multiple layout configuration for tool windows in Android Studio. If so how?
Thanks,
George
Go to menu window > Store current layout as default
A bit late to the party, but there is a newer plugin, that works much better imho.
You can define 4 layouts, it can switch layouts immediately, it also (re-)stores the floating state of each panel and so on:
https://plugins.jetbrains.com/plugin/13005-window-layout-manager
There is an IntelliJ IDEA plugin preserve-layout-plugin that allows you to that. It's available in the plugin repository, just search for preserve.
By default, you need to restart the IDE or open another project in order to load the layout but the following works as well: you import the layout, you store it as default, and then you restore the default layout.
The following method helped me.
1) Run Android Studio as administrator.
2) Now, arrange the tabs as you want.
3) Go to Window->Store current layout as default.
This is something I missed when I started Android development especially after using multiple layout in Unity Editor before this.
However, I found this plugin - "Window Layout Manager" Link which you can also find and install via Android Studio plugins marketplace.
Allows you to arrange different windows/components like terminal, logcat, project explorer etc and save it with a name.

Android studio no main activity, no layouts on a new project

I installed new Android Studio. I created new Project and asked the wizard to create main activity. But there were no layouts, no main activity class, no nothing. Error on trying to make new Java class files. The new project tree looks like this:
No (main/java) folder.
No (res/layout) folder.
Other words project is useless.
From what i learned is that you may be picking the "no layout" option when prompted to pick one. Try picking the basic activity and the rest of the files will show
After creating the project, you need to go to File menu and then Import Project. Then browse to the location of your project and import it. Then you will see all of these files and folders. I had this problem too, and it seems to be something that they overlooked in the newer versions of Android Studio (which is quite pathetic if you ask me).
Empty Activity
Choose "Empty Activity" instead of "No Activity",
while creating a NEW PROJECT in Android Studio.
I don't know if anyone is having the same problem right now but i solved this issue by changing the Android Gradle plugin version and the Gradle version.
For doing this you have to open the project you're having issues with and click on
File->Project Structure->Project
and there you will see the two options.
Android Gradle Plugin Version 4.0.0 and Gradle version 6.1.1 worked for me. After that I went to the file directory, right click on the package folder "com.example.myProject" and manually created an empty activity. The layout folder with my new activity was created automatically after that.
I found it's because I changed the Java runtime version before through the Android Studio plugin Choose Runtime. I changed to JDK 8 from JDK 11 then the problem occured. It worked for me to change back to JDK 11 through plugin Choose Runtime.
Try
Typing main activity (without quotes) in the search box and
Press enter.
For me it got restored. Search window is useful in finding many hidden tools quickly.
I created a new activity by right clicking on java then selected activity and the layout file was automatically written
When you open a new project, you can't select "empty project" you have to select and activity project. I just went through this had to delete my project and start a new one now everythings there.

Resources