Pumych
Pumych

Reputation: 1398

android.widget.TextView vs TextView

Both of them link to the same TextView.java file and looks the same on design tab. The question is, when I should use the short one <TextView ... /> and when the long one <android.widget.TextView />

Can I use, for example <ConstraintLayout> instead of <android.support.constraint.ConstraintLayout> (both link to the same ConstraintLayout.class but looks different on design tab), and how do I know how to use the widgets and other "components" from android reference

Upvotes: 0

Views: 850

Answers (3)

Manohar
Manohar

Reputation: 23404

The question is when I should use the short one <TextView ... /> and when the long one <android.widget.TextView />

Both are the same things you can use any one , Better to use <TextView ... /> as most developers use it and it's less code to write .

Can I use for example <ConstraintLayout> instead of <android.support.constraint.ConstraintLayout>

No you can't it does not come with default in android , you have to use a separate support library to use it implementation 'com.android.support.constraint:constraint-layout:1.1.3'

how do I know how to use the widgets and other "components" from android reference

Any thing with package android.widget.xxxx or android.view.xxxx use xxxx directly for others use full package name in layout .

You can see the classes which comes under android widget over here and classes which comes under android view over here

Upvotes: 1

tynn
tynn

Reputation: 39853

When it comes to default widgets you find in the android.view and android.widget packages of the Android framework, you can ommit the package name, as it's implicitly searched anyhow.

Since the ConstraintLayout is not a default widget, you cannot ommit the package name with it.

Additionally to the default widget packages, AndroidX replaces the inflater components resolving the actual classes, thus <TextView> actually resolves to AppCompatTextView instead, so better don't use the quallified name of the class like <android.widget.TextView>.

Upvotes: 3

Jude Osbert K
Jude Osbert K

Reputation: 1048

<TextView /> and <android.widget.TextView /> are the same. You can use it interchangeably because they are part of the basic components of Android. However, in case in of ConstraintLayout it comes as a part of the support library that you added to to the build.gradle file in your app. To access a class from that you need to fully tell the xml that you want ConstraintLayout from that specific package.

Upvotes: 1

Related Questions