亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將鏈接更改為可在 TextView 上單擊的自定義字符串

將鏈接更改為可在 TextView 上單擊的自定義字符串

jeck貓 2024-01-05 10:01:42
我有鏈接https://google.com。我希望該鏈接只需更改為字符串“google”TextView 中顯示的是“google”但實際上在谷歌有鏈接https://google.com。并且可以點擊我有 XML:<TextViewandroid:id="@+id/social"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="30dp"android:layout_marginTop="350dp"android:autoLink="web"android:linksClickable="true"android:text="in here social"/>我有Java課程: TextView social = (TextView) findViewById(R.id.social); String text = "<a href='https://google.com'> Google </a>"; social.setText(Html.fromHtml(text));
查看完整描述

3 回答

?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

嘗試這個:


 TextView t2 = (TextView) findViewById(R.id.text2);

t2.setMovementMethod(LinkMovementMethod.getInstance());

在 xml 中:


<TextView

android:id="@+id/text2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/txtCredits"/>

如果您正在調用,請在 xml 中刪除自動鏈接setMovementMethod()。


查看完整回答
反對 回復 2024-01-05
?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

您可以將網址保存在標簽中,如下所示:

social.setTag("https://google.com");

當你想獲取 url 時,請執行以下操作:

String url = (String) social.getTag();


查看完整回答
反對 回復 2024-01-05
?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

Alhamdulillah 我的問題已經解決了


在你的XML中:


<TextView

android:id="@+id/social"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="30dp"

android:layout_marginTop="350dp"

android:linksClickable="true"

android:text="@string/social"/>

在你的價值觀字符串中


<string name="social">in here social</string>

在你的java類中


TextView mSocial = (TextView) findViewById(R.id.social);

mSocial.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_VIEW);

                intent.setData(Uri.parse(https://google.com));

                startActivity(intent);

            }

        });

將您的 TextView 設置為字符串“Social”,但如果單擊 TextView 可以轉到 google.com


查看完整回答
反對 回復 2024-01-05
  • 3 回答
  • 0 關注
  • 183 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號