6

从我的 PreferenceScreen 我想在 WebView 而不是浏览器中打开链接。有任何想法吗?

这是我的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>

所以 URL 在哪里我想打开一个 Android WebView,而不是打开手机的浏览器。

4

1 回答 1

8

您应该在您的首选项上使用点击监听器,当它被点击时,打开您的活动。

在 XMl 中,将 PreferenceScreen 替换为 Preference 并给它一个键

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

然后在您的偏好活动中,加载偏好文件后:

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

其中 myListener 是一个内部类的实例,它将启动您的活动并传递 url 以在意图中打开额外数据。

问候, 斯蒂芬

于 2011-06-16T16:59:04.157 回答