在preferences.xml中使用PreferenceScreen

Won*_*ane 2 android android-preferences preferencescreen

我的Google-Fu今天失败了这个Android新手.

有没有人知道如何从PreferenceScreen启动一个意图?

就像是:

    <PreferenceScreen
        android:key="preference_some_new_layout"
        android:title="@string/pref_some_title">

            <intent android:action="????" /> 

    </PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

我想展示一个自定义的LinearLayout,它允许我设置一些半复杂的首选项.

最好的方法是什么?

谢谢,wTs

Bry*_*nny 5

I've used a custom dialog box before for a preference. Is this sort of what you need? Here is an example from my open source app.

And here is the XML to add the preference to a PreferenceScreen.

<net.mandaria.tippytipper.preferences.DecimalPreference
                        android:key="exclude_tax"
                android:title="Tax Rate to Exclude"
                android:summary="The tax rate to exclude when calculating tip"
                android:dialogMessage="Tax Rate"
                android:defaultValue="0"
                android:dependency="enable_exclude_tax_rate"
                />
Run Code Online (Sandbox Code Playgroud)

This will let you produce complex preferences in a DialogPreference (you might be able to swap this out if you don't need a Dialog, someone else will have to fill that in for you because I've never tried) that look like this:

alt text