Android hyperlinks on TextView in custom AlertDialog not clickable

前端 未结 3 1590
别那么骄傲
别那么骄傲 2020-12-11 05:37

Following my previous question I still have problems managing hyperlinks on my custom AlertDialog but I believe I narrowed down the problem because I think it o

相关标签:
3条回答
  • 2020-12-11 05:43

    Try this

    setText(Html.fromHtml(String));
    
    0 讨论(0)
  • 2020-12-11 05:44

    You defined the TextView without android:autoLink="all" , android:clickable="true" & android:linksClickable="false"

    For info.xml TextView as below

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/infoDetailText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp" />
    
    0 讨论(0)
  • 2020-12-11 05:52

    Anyway, your code works perfectly,...

    Code for AlertDialog:

    LayoutInflater inflater = LayoutInflater.from(ctx);
    View layout = inflater.inflate(R.layout.info, null);
    AlertDialog.Builder about = new AlertDialog.Builder(ctx);
    about.setTitle("Data");
    about.setIcon(R.drawable.info);
    
    // Make the textview clickable. Must be called after show()
    TextView textView = (TextView) layout.findViewById(R.id.infoDetailText);
    textView.setText(R.string.link_text_manual);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    about.setView(layout);
    AlertDialog displayInfo = about.create();
    displayInfo.show();
    

    Code of TextView XML:

    <TextView
        android:id="@+id/infoDetailText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/infoVersionTitle"
        android:padding="4dp" />
    

    Removed two attributes..

    android:autoLink="all"
    android:linksClickable="true"
    
    0 讨论(0)
提交回复
热议问题