Domanda

Dal mio screen preference voglio aprire collegamenti in WebView non browser. Qualche idea?

Ecco parte del mio 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>

Quindi, dove sono gli URL, voglio aprire un webview Android, non aprire il browser del telefono.

È stato utile?

Soluzione

Dovresti utilizzare un ascoltatore di clic sull'elemento delle preferenze e quando è stato fatto clic, apri la tua attività.

In XML, sostituire il schermo delle preferenze con una preferenza e dargli una chiave

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

Quindi nell'attività di preferenza, dopo aver caricato il file di preferenza:

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

Dove MyListener è un'istanza di una classe interiore che lancerà la tua attività e passerà l'URL per aprire dati extra intenti.

Saluti, Stéphane

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top