Monday, May 13, 2019

How to Textview new line in Android

How to Textview new line in Android

Hello everyone, today a beginner slopes for example about Textview new line of android, so that you can reference and apply to your application.
To display the line in the Textview Android be much you can do step by step as follows.

Create a file Xml have name : activity_main.xml
<LinearLayout
    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"
    android:orientation="vertical"
    android:layout_margin="25dp"
    tools:context=".MainActivity"
    >

    <TextView
        android:id="@+id/text_view1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:background="#DEB887"
        android:text="This is line 1 \nThis is line 2 \nLine number 3"
        />

    <TextView
        android:id="@+id/text_view2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:background="#DA70D6"
        android:text="This is line 1 \nThis is line 2 \nLine number 3"
        android:maxLines="2"
        />

    <TextView
        android:id="@+id/text_view3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:background="#8FBC8F"
        android:text="This is line 1 \nThis is line 2"
        android:minLines="3"
        />

    <TextView
        android:id="@+id/text_view4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:background="#5F9EA0"
        android:text="@string/Multiline_Text_By_N"
        />

</LinearLayout> 
Create string in string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My Application5</string>
    <string name="action_settings">Settings</string>
    <string name="Multiline_Text_By_N">
        Line number 1 \nLine number 2
    </string>
</resources>


How to Textview new line in Android

No comments:

Post a Comment