Using XML layout for TextView

余生颓废 提交于 2019-12-13 00:58:56

问题


I use Xamarin and I have the following code:

base.OnCreate (bundle);

TextView textView = new TextView (this.ApplicationContext);
textView.AutoLinkMask = Android.Text.Util.MatchOptions.PhoneNumbers; 
textView.Text = "This is a phone number 0800 32 32 32";

//Linkify.AddLinks(textView, MatchOptions.PhoneNumbers);

SetContentView(textView);

Can I please have some help to do the same code but with resource layout files instead?

Thanks in advance


回答1:


textview.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a phone number 0800 32 32 32"
android:autoLink="phone">
</TextView>

In onCreate just mention

setContentView(R.layout.textview);



回答2:


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/textview"
  android:text="This is a phone number 0800 32 32 32"
  android:autoLink="phone"
/>


来源:https://stackoverflow.com/questions/21200507/using-xml-layout-for-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!