相关疑难解决方法(0)

Android以编程方式设置autoLink属性

<TextView
    android:text="123456789"
    android:autoLink="phone">
</TextView>
Run Code Online (Sandbox Code Playgroud)

我想从代码中创建这个TextView,但是我遇到了无数的问题.

首先,我中途创建一个TextView并添加:

tw_phone.setAutoLinkMask(0x04);
Run Code Online (Sandbox Code Playgroud)

这导致了一个可点击的TextView,但是当你点击时,一个toast说"没有应用程序可以执行此操作"或类似的东西.我也尝试过

Linkify.addLinks(tw_phone, Linkify.PHONE_NUMBERS); //and .ALL
Run Code Online (Sandbox Code Playgroud)

但它给了我相同的结果.

当我决定在StackOverflow上询问时,我试图剥离我的代码,因为我使用Layouts(你永远不知道)的方式有问题,但现在我甚至无法使TextView可点击.在我看来,这是代码应该工作的代码,因为它只是我在代码中使用的更精简的版本.

TableLayout table = (TableLayout) findViewById(R.id.tableResult);
TableRow row = new TableRow(this);
TextView tw = new TextView(this);
tw.setText("123456789");
tw.setAutoLinkMask(Linkify.ALL);
row.addView(tw);
table.addView(row);
Run Code Online (Sandbox Code Playgroud)

有人可以写一个简单的小例子来创建一个TextView,给它一个数字作为文本然后允许用户点击它并选择他们想要打开数字的任何应用程序吗?如果你能指出我的代码中的错误,那将是很好的,但我宁愿直接得到答案.我尝试的东西取自其他StackOverflow问题和答案.

java android linkify

9
推荐指数
1
解决办法
7039
查看次数

活动需要FLAG_ACTIVITY_NEW_TASK标志

我正在使用Xamarin,当我点击具有电话号码链接的TextView时,我的模拟器正在执行错误.

应用程序输出具有以下输出:

[MessageQueue-JNI] Exception in MessageQueue callback: handleReceiveCallback
[MessageQueue-JNI] android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Run Code Online (Sandbox Code Playgroud)

我需要在哪里设置标志,我应该将其设置为什么?

我可以请一些帮助让这个工作吗?

提前致谢.

编辑

这是我的应用程序代码:

namespace TestTextViewAutoLink
{
    [Activity (Label = "TestTextViewAutoLink", MainLauncher = true)]
    public class MainActivity : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            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); …
Run Code Online (Sandbox Code Playgroud)

c# android textview android-activity xamarin

4
推荐指数
2
解决办法
7595
查看次数

标签 统计

android ×2

android-activity ×1

c# ×1

java ×1

linkify ×1

textview ×1

xamarin ×1