Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a hyperlink into a Preference Screen (PreferenceActivity)

I would like to add three hyperlinks a Preference screen, which makes use of the PreferenceActivity if possible. Can I do this, if so, could someone provide support?

Many thanks,

like image 602
user2511675 Avatar asked Jul 13 '13 22:07

user2511675


2 Answers

You don't want "hyperlinks", then. You want entries in the PreferenceScreen that, when tapped, launch some activity, such as to bring up a Web page on your desired URL.

That is covered by the <intent> element:

<Preference android:title="@string/prefs_web_page" >
    <intent android:action="android.intent.action.VIEW"
            android:data="http://www.example.com" />
</Preference>

Include those in your preference XML that you use to populate your PreferenceScreen, and when the user taps on the preference entry, your requested activity will start.

like image 191
CommonsWare Avatar answered Sep 25 '22 22:09

CommonsWare


Java version is something like this:

PreferenceScreen link = man.createPreferenceScreen(this);
this.setIntent(new Intent().setAction(Intent.ACTION_VIEW).setData(
           Uri.parse("https://rogerkeays.com")));
link.setTitle(R.string.link_title);
link.setSummary(R.string.link_summary);

// add to containing group
// group.addPreference(link);
like image 28
Roger Keays Avatar answered Sep 24 '22 22:09

Roger Keays