Reputation: 711
I've done a lot of search but can't find the difference between tools:visibility = "visible"
and android:visibility = "visible"
? Which situation I must use tools or android?
Upvotes: 27
Views: 8575
Reputation: 4497
The exactly question should be
"What the difference between
android:...
andtools:...
on Layout XML files"
tools is one of the Design Attributes that can facilitate layout creation in XML in the development framework.This attribute is used to show the development framework what activity class is picked for implementing the layout. Using “tools:context”, Android Studio chooses the necessary theme for the preview automatically
Android is used in run-time app, when you launch your apk in a device
according to here
Upvotes: 5
Reputation: 2609
tools: attributes only contribute to design time preview while editing layouts while
android: actually affects how it will be displayed on actual device.
You can find further information here and here.
Upvotes: 11
Reputation: 3455
If you see the Design Time Layout Attributes
The tools namespace is a specially recognized namespace by the Android tools, so all the attributes you define on view elements in the tools-namespace will be automatically stripped when the application is packaged and there is no runtime overhead.
So if we need to test something in layout editor only during development time which doesn't affect at runtime, we can use the tools
namespace.
Example:
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First"
tools:visibility="invisible" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second"
tools:visibility="visible" />
If the above layout is rendered in Android Studio designer view, first Button will be invisible. But at run time, it will be visible.
Upvotes: 3
Reputation: 615
TOOLS values will be used only in layout preview in Android Studio.t
ANDROID values will be used in app as normal.
So if you set values for main container: tools:visibility:"gone" android:visibility:"visible"
The main container in layout preview in AS will be gone, but if you launch app on emulator / device it will be visible.
Upvotes: 2
Reputation: 5370
Here is the Simple Explanantion:
tools:visibility = "visible"
is used to manipulate view visibility on the IDE.It wont affect the view in the real time.It just used for Designing purpose in Android Studio
while
android:visibility = "visible"
is the actual code which will be executed in run-time and will make changes to your views
Ref: http://tools.android.com/tips/layout-designtime-attributes
Upvotes: 65