Recently I started using Material 3 Design components in my app.
For some reason though, the design view goes invisible when using certain Material 3 components in my xml code.
As soon as I delete them from my xml code, the design view works again.
The weird thing though, is that they are being displayed correctly when I launch my app with the layout that contains the components.
The components that cause the design view to be invisible are e.g. TopAppBar, MaterialCardView & BottomAppBar.
This is how it looks when I launch the app:
And this is how my design view looks:
Clean project, rebuild project and invalidate caches didn't help.
Any ideas what causes this behaviour?
Edit: I found a solution. Downgrading from com.google.android.material:material:1.8.0-rc01 to com.google.android.material:material:1.7.0-rc01 fixed the issue.
Related
I've an application that uses Fragmnent Views with XML resources and I want to migrate it to Compose. Being the app quite big, I decided to temporarily have a mixed environment with Compose working together with the old XML resources, so I created a new Compose fragment and I succeeded to add the standard navigation action to navigate to it. The code builds successfully, but when I try to run the app I get the error of the picture below. It is particularly wierd because this error appears immediately, and not in the build panel, but in a popup dialog. Any hint ?
Ok, the documentation is not very clear, but in the end I found this:
"You can also include a ComposeView directly in a fragment if your full screen is built with Compose, which lets you avoid using an XML layout file entirely."
Being my app a hybrid one with XML navigation graphs, it looks like I need to define an XML resource anyway.
I hoped I cound avoid defining an XML layout, but it seems I need one for a fragment that has an old fashioned Activity as parent.
I'll post an update as soon as I discover something new
UPDATE
Adding an XML layout didn't fix the problem.
In fact the XML layout is not necessary. I don't really understand the cause of that error, but after cleaning a couple of times the project and clearing A.S. cache it disappeared. I succeeded to add a Compose Fragment to an old XML resources style app. The old navigation works without problems. Hope this post will help someone else save the time I have wasted...
I have a somewhat complex layout.xml file (353 xml lines, 16kb) with multiple nested constraint layouts. This particular xml file is only showing a blank white screen in the design tab but works well when I run it on device and emulator. I have other smaller layout files which show the design normally on android studio but it seems that there is a bug with viewing larger xml files.
Is this a known issue? I tried refreshing layout and removing android studio cache but nothing seems to work. any ideas?
I do not think it has anything to do with the code since it runs normally on device and I am not sure posting the whole xml file on SO is a good idea.
update
What I realised is that all the elements in the layout seem to be 'invisible' at the top left corner since when I hover over them the pointer turns into a hand and when I click , certain elements get highlighted in the component tree. This is a screenshot of what I am seeing:
I added android:visibility="gone" which is vital to my app. Little did I know that it also applies to the design view which I find to be really useless. I want the visibility to be gone during runtime, not on a platform where I am supposed to be tweaking the design of the UI. This is ridiculous to me.
Does anyone know If I can keep visibility="gone" but still see the design in the design view of the layout?
You can use tools:visibility="visible" for designing purposes.
It has zero effect on the view in real use.
Don't forget to keep your android:visibility="gone".
In general, use tools attributes whenever you'd like to manipulate a preview in the designer while keeping your view attributes valid for real use.
Edit:
Keep in mind that there is a huge difference between invisible and gone. More about that
The Design view in Android Studio is just blank for me. I've already followed the advice in this link but it doesn't work. If I right click ConstraintLayout and then Convert view it opens a window where I can click RelativeLayout but this doesn't work. Does anyone have any advice?
I had this problem earlier this week. Everything I selected for my ConstraintLayout was invisible for a new project. I ended up selecting a different theme and it woke up after that and started showing the picked views.
Screenshot Attached:
On the right on the API number ["28" in my case]. Click on the theme [NoActionBar in my case]. I think if you try a few different themes they will eventually become visible again.
This is what my palette looks like, I want to know how to add other tabs like design and appCompact.
Thank you
I'm not sure I understand what you are asking. The palette cannot be modified and is a container for components such as button, texts, etc.
Please refer to this for intro into Android Development.
AppCompact is a support library that allows for themes, colors, widgets, etc. to run on earlier devices i.e. backward compatibility.
The design view is accessed through the res folder in the layout folder. By default, called activity_main.xml.
You should go through the basics of android development so you can understand the structure, components and overview of android Studio.
EDIT:
See this link which shows you how to create custom view components
Please view this link which goes over the entire overview of the UI and how to use and customise the UI layout design(Very Useful!).
The folks that works on Android Studio redesigned the Palette window in Android Studio 3.1.2. Some of these widgets have been completely taken out.
"There is a new "Legacy" section and the "Advanced" section has gone. Along with it the NumberPicker, DataPicker, TimePicker, TextClock, Chronometer and, as far as I can see, the Transitions category has gone completely along with all its widgets."
"If you rely on any of the missing Widgets then my advice is don't upgrade until a workaround has been made available. There is no word from the Android Studio team as to why these widgets have been removed and no word on how to put them back."
After the update to 2.2 the designer seems to gone crazy.
I using API 24 with Build Tools Version 24.0.3.
Into the designer if i have a parent GridLayout or the v7:
I can't drag the first subview inside. The only solution i found is that to drag it into the Component Tree.
If i add two subviews, i can't arrange them by dragging inside the designer, before the 2.2 version of android studio the columns and the rows was , now it shows this error and stops to respond:
java.lang.NullPointerException
at com.android.tools.idea.uibuilder.handlers.grid.GridDragHandler.commit(GridDragHandler.java:56)
at com.android.tools.idea.uibuilder.surface.DragDropInteraction$1.run(DragDropInteraction.java:191)
at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
at com.intellij.openapi.command.WriteCommandAction$2.run(WriteCommandAction.java:108)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:124)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:99)
at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:103)
at com.intellij.openapi.command.WriteCommandAction.access$000(WriteCommandAction.java:34)
at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:85)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:723)
at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:82)
at com.android.tools.idea.uibuilder.surface.DragDropInteraction.moveTo(DragDropInteraction.java:203)
at com.android.tools.idea.uibuilder.surface.DragDropInteraction.end(DragDropInteraction.java:123)
...
Sometimes into the designer if i click one subview of the GridLayout it goes at the bottom of the superview, in xml preview too!!!
Now the designer doesn't allow me to copy components between 2 different layouts ( i have to copy it from xml ).
If a property of a view is selected into the right panel ( for example : text for a TextView ) and i press delete, it deletes the components instead of resetting the property ( i have to delete the line from xml ).
It should be the stable version, but in my opinion, it's not usable like before, now i have to manually modify the xml more then before.
I already tried to clear all like: Described here and then reinstall it. But it's the same.
It's something that i am missing?