Add “More” at the end of textview after 2 lines in Xamarin Android

how to archive like below text view, when am clicking it will show full content of text view.

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    First, set ellipsize of TextView to 'end'. Then add click event ,set ellipsize to null and SetSingleLine to false.
    You can refer to the code.
    layout.xaml

    <TextView 
        android:id="@+id/text"
        android:text="In this code example, the EditText attribute android:imeOptions is set to actionGo. This setting changes the default Done action to the Go action so that 
        tapping the Enter key triggers the KeyPress input handler. (Typically, actionGo is used so that the Enter key takes the user to the target of a URL that is typed in.)
        To handle user text input, add the following code to the end of the OnCreate method in MainActivity.cs:"
        android:lines="4"
        android:ellipsize="end"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"/>
    

    Activity.cs

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.layout);
    
        TextView text = FindViewById<TextView>(Resource.Id.text);
    
        text.Click += delegate
        {
            text.SetSingleLine(false);
            text.Ellipsize = null;
        };
    }
    

Sign In or Register to comment.