Custom PreferenceScreen in PreferenceScreen

社会主义新天地 提交于 2019-12-11 11:33:44

问题


I have a standard preference page in my app. But from this preference page i want the user to be able to navigate to an other PreferenceScreen with a custom layout, when user presses "Manage Favorits.

This is the custom layout i have in mind:

Is it possible to use custom layout on "sub-preference-screens"?

Thanks!


回答1:


Yes, you can launch a separate activity using intent.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <PreferenceScreen android:title="@string/your_title"
    android:summary="@string/your_string">

        <intent android:targetClass="your.package.YourClass"
            android:targetPackage="your.package" />
    </PreferenceScreen>

</PreferenceScreen>

As long as you want to specify your own layout you would need to extend Preference class.

Use setLayoutResource() to define your layout in your constructor. Constructor needs to be

public YourClass(Context context, AttributeSet attrs) {
        super(context, attrs);
        setLayoutResource(R.layout.your_custom_layout);
    }

You can also check this.



来源:https://stackoverflow.com/questions/7668293/custom-preferencescreen-in-preferencescreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!