03 Aug Android TextView Control
Android TextView Control is a control that shows text to the user. If you want to show a text view for editor, use EditText, which is a subclass of TextView. It doesn’t allow editing, but it’s subclass EditText provide editing options.
Usage
It is used to show the text view like a label. Let’s say you want to add a label on your app, i.e. Our new features, then you can add it with TextView.
Example
Now, we will write the code xml file, which has a TextView and EditText. Follow the below code,
activity_main.xml
For src\main\res\layout\activity_main.xml,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/top_title" android:textSize="20dp" android:layout_centerHorizontal="true" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/name" android:layout_centerInParent="true" android:layout_below="@id/textView1" /> </RelativeLayout> |
AndroidManifest.xml
The content of \src\main\AndroidManifest.xml, provides key information of your app to the system. The system needs this to run your code,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.studyopedia.studyopediaapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
strings.xml
Here’s the code for res/values/strings.xml. The app name and any hardcoded strings will be visible,
1 2 3 4 5 6 7 |
<resources> <string name="app_name">StudyopediaApplication</string> <string name="name">Enter your name</string> <string name="top_title">Working on an example Android App</string> </resources> |
Output
It shows our TextView, which shows the following text at the top: Working on an example Android app
We will also see an EditText, where user can enter value i.e. name,
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
No Comments