Reputation: 53
I have a simple question. I'm making application in Android Studio and I have got a problem. My application is creating buttons using Java. I want see these buttons in Preview editor, because I want have easier posibility to editing layout. So I made the same buttons in XML, but here is the problem. When I build my app it is showing both buttons! I want see only the buttons creating by Java code and finally here is my question it is possible remove buttons created in XML? I was thinking about tools:.. but I didn't find any usefull tag. Someone have any idea?
Upvotes: 3
Views: 1714
Reputation: 28238
As already mentioned, you use tools:visibility="visible"
in combination with android:visibility="gone"
to render any view in preview but not in the build.
Using removeView(someChildElement)
on your layout will remove the element you don't want. AFAIK, the XML code will still be there in the APK, but it isn't there at all in the built APK.
I have no clue why you want to show them in preview and not in the finished result. If it is because you want to toggle them manually later, you don't need any XML code. You can also do:
someView.setVisibility(GONE)
And a quick reference:
You cannot remove the code from the XML file on build though.
Upvotes: 2
Reputation: 7918
You can use tools:visibility="visible"
and android:visibility="gone"
together, so they show in the preview, but they're gone when the app is running on a device/emulator.
Upvotes: 8