Open a WebView, not a browser, from the preferences screen.

From my PreferenceScreen, I want to open links in a WebView, not a browser. Any ideas?

Here is part of my xml:

<PreferenceCategory android:title="@string/about"> <PreferenceScreen android:title="@string/eula" android:summary=""> <intent android:action="android.intent.action.VIEW" android:data="http://www.tara.com/m/EULA.aspx" /> </PreferenceScreen> <PreferenceScreen android:title="@string/privacy_policy" android:summary=""> <intent android:action="android.intent.action.VIEW" android:data="http://www.tara.com/m/Legal/Privacy.aspx" /> </PreferenceScreen> <PreferenceScreen android:title="@string/version" android:summary="@string/version_name"> </PreferenceScreen> <PreferenceScreen android:title="@string/customer_support" android:summary="@string/email_description"> <intent android:action="com.tara.android.turboweather.EMAIL_ACCUWX" /> </PreferenceScreen> <PreferenceScreen android:title="@string/branding" android:summary=""> </PreferenceScreen> </PreferenceCategory> 

So, where are the URLs I want to open Android WebView, do not open the phone browser.

+6
source share
1 answer

You must use the click listener in your preference item, and when you click it, open your activity.

in XMl, replace PreferenceScreen by preference and give it a key

 <Preference android:title="About" android:summary="Details about the app" android:key="aboutPref" /> 

then in your activity preferences, after loading the settings file:

 Preference pref = findPreference( "aboutPref" ); pref.setOnPreferenceClickListener( myListener ); 

where myListener is an instance of the inner class that will start your activity and pass the url to open in the extra data.

Regards, StΓ©phane

+8
source

Source: https://habr.com/ru/post/890699/


All Articles