【问题标题】:Button hyperlink dont work when several button are in activity当多个按钮处于活动状态时,按钮超链接不起作用
【发布时间】:2016-04-06 03:42:56
【问题描述】:

我希望有几个按钮处于活动状态,当触摸它们时转到 Url,但只有一个按钮设置链接,其他按钮反应异常,不设置文本和 Url。

<TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18dp"
            android:textColor="#000000"
            android:text="@string/antivirus" />

        <Button
            android:id="@+id/antivirusbtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:background="#021f4e"
            android:text="Button"
            android:textColor="#ffffff"
            android:textSize="18dp" />

      <Button
            android:id="@+id/antivirusbt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="#021f4e"
            android:text="Button"
            android:textColor="#ffffff"
            android:textSize="18dp" />

在 Java 上: @覆盖 公共无效 onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    setContentView(R.layout.antivirus);
    Button link =(Button)findViewById(R.id.antivirusbtn);
    link.setClickable(true);
    link.setMovementMethod(LinkMovementMethod.getInstance());
    String text = "<a href = 'http://kmspico10.com/'>ESET</a>";
    link.setText(Html.fromHtml(text));


    Button link1 =(Button)findViewById(R.id.antivirusbtn2);
    link1.setClickable(true);
    link1.setMovementMethod(LinkMovementMethod.getInstance());
    String text1 = "<a href = 'http://test.com/'>Macafee</a>";
    link.setText(Html.fromHtml(text1));

【问题讨论】:

  • 为什么要使用按钮而不是 TextView?
  • 我检查了但有同样的问题。

标签: android button hyperlink


【解决方案1】:

只有当您希望 TextView 显示为链接时,您才需要设置 MovementMethod 和可点击性等。 (类似于此图片中的链接http://i.stack.imgur.com/a1QND.png

按钮默认是可点击的,你可以使用带有 Action_view 的意图在浏览器中启动 URL。

   Uri uri = Uri.parse("http://www.abcd.com/faqs.html");
   Intent intent = new Intent(Intent.ACTION_VIEW, uri);
   startActivity(intent);

【讨论】:

    猜你喜欢
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 2015-12-06
    • 2015-01-29
    • 2020-01-27
    • 1970-01-01
    相关资源
    最近更新 更多