Pages

Thursday, September 8, 2016

Android TextView Example with String

activity_main.xml
<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello Programmer!" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="110dp"
        android:text="@string/my_text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>
MainActivity.java
package in.kantapp.example2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

string.xml
<resources>
    <string name="app_name">Example 2</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="my_text">Definition of text!</string>

    <string-array name="operating_systems">
        <item>Android</item>
        <item>iPhone</item>
        <item>Windows Mobile</item>
        <item>Linux </item>
        <item>Windows 7.0</item>
        <item>Windows 8.0</item>
        <item>Windows 8.1</item>
        <item>Chrome OS</item>
        <item>Unix</item>
        <item>Symbian</item>
    </string-array>
</resources>

No comments:

Post a Comment