Friday, 24 August 2018

Xamarin Textview

RANGE INPUT GENERATORXmarin TextView is a control for displaying text in Xmarin Layout. TextView accept text from string.xml file or you can directly write the text in the TextView control. 

Here is example of TextView displaying text directly. 


<TextView
          android:text="Hellow World"
         android:layout_width="match_parent"
          android:layout_height="wrap_content"
         android:id="@+id/textView1"
         android:textColor="#ffffff"/>


Here is the example of TextView displaying text from string.xml. 


string.xml

<resources>
     <string name="hellow_world">Hellow World</string>
</resources>

Here is the control

<TextView
       android:text="@string/hellow_world"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/textView1"
        android:textColor="#ffffff"/>

The TextView is fully Programmable, you can display text from program also. Here is the example.

Here is the control
<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1"
        android:textColor="#ffffff"/>

Here is program source code
 
TextView txtNm = FindViewById(Resource.Id.textView1);
txtNm.Text="Hellow World";

Here is the output , how all three above look like

 


If TextView comes with variety of property and options.TextView can be single line or multi line.Setting  Single line property to false and line number control the number of line and text line in the Layout.


Here is the Example of a single line TextView 

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:singleLine="true"
android:textColor="#ffffff"/>



Here hair is the example of multi line  TextView.

 
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/textView1"
android:singleLine="false"
android:maxLines="5"
android:textColor="#ffffff"
android:text="Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World" />





TextView text size can be control and fore color back ground color also can be control. Here is the example textsize to 30 and back
ground color yellow and fore color to red.


<TextView
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:id="@+id/textView1"
          android:singleLine="true"
          android:textColor="#F0C94C"
          android:textSize="30dp"
          android:text="Hellow World"
          android:background="#DB483B"/>



 

TextView display position can be seat from gravity property.Position  of the control Top ,Bottom ,Left, Right of its  parent can be handled. 


Here is the example


<TextView
      android:layout_width="match_parent"
      android:layout_height="100dp"
      android:id="@+id/textView1"
      android:singleLine="true"
      android:textSize="15dp"
      android:text="Hellow World"
      android:background="#DB483B"
      android:gravity="center"/>






TextView event can be handled by event handler method. Here is the example of  how click event can we handle of a text to control.


Layout File

<TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/textView1"
        android:singleLine="true"
        android:textSize="15dp"
        android:text="Hellow World"
        android:background="#DB483B"
        android:gravity="center"/>

Activity

 
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;

namespace App5
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class LoginActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.activity_main);

TextView txtNm = FindViewById(Resource.Id.textView1);
txtNm.Click += (sender, e) =>
{

         Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
         Android.App.AlertDialog alert = dialog.Create();
         alert.SetTitle("Hi");
         alert.SetMessage("You have Clicked TextView");
          alert.SetButton("OK", (c, ev) =>
          {
                  });
                alert.Show();
          };
       }
   }
}

Output:

 

No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...