2

こんにちは、次のコードを使用して電子メール アドレスと URL をリンクしていますが、必要に応じて機能していますが、URL と電子メール以外の場所をクリックすると、リンクされていない白いテキストが黒くなり、読めなくなります。大したことではありませんが、リンクされていないテキスト onclick の色の書式設定に関するヘルプを煩わせているだけで、大歓迎です。

            final SpannableString s = new SpannableString("Some text here before link http://www.google.com some more text then email fake@fake.com");
        Linkify.addLinks(s, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
        final AlertDialog d = new AlertDialog.Builder(MainMethod.this)
            .setPositiveButton(android.R.string.ok, null)
            .setIcon(R.drawable.about)
            .setTitle(R.string.about_title)
            .setMessage( s )
            .create();
        d.show();
        ((TextView)d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());

したがって、次のテキスト「リンクの前にいくつかのテキストがあり、次に電子メールが送信されます」は、ダイアログで白く表示されますが、押すと黒くなります

編集:

ジャワ

       LayoutInflater li = LayoutInflater.from(this);
       View view = li.inflate(R.layout.link, null);
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
       builder.setTitle("Insert Title Here");
       builder.setView(view).create().show();
       TextView text=(TextView) findViewById(R.id.link1);

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <TextView
   android:id="@+id/link1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Body text with email fake@fake.com and a website http://google.com"
   android:autoLink="web|email"
   android:textColorLink="#0000ff"
   android:textColor="#ffffff"
  />

</LinearLayout>
4

2 に答える 2

2

これはおそらく正しい方法ではありませんが、明示的に textColor 属性を設定すると、この問題を回避できます。

<TextView android:id="@+id/text1" 
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content" 
    android:autoLink="all"
    android:textColor="#ffffff"/>

テキストの色を設定するときにスタイルを使用するように注意しなかったとしたら、私は気が進まないでしょうが、それはあります。

于 2011-03-29T00:27:20.390 に答える
0

これをXMLのTextViewに設定します

android:textColor="@android:color/secondary_text_dark_nodisable"

この回答も参照してください。

于 2011-06-19T16:04:50.667 に答える