How to add a button to a PreferenceScreen?

后端 未结 10 1200
抹茶落季
抹茶落季 2020-11-28 20:48

I\'m quite new to Android Development and just came across Preferences. I found PreferenceScreen and wanted to create a login functionality with it. The only pr

10条回答
  •  有刺的猬
    2020-11-28 21:22

    You can also customise the layout of a Preference by overriding Preference.onCreateView(parent). The example below uses an anonymous inner class to make red preferences.

        screen.addPreference(
            new Preference(context) {
                @Override
                protected View onCreateView(ViewGroup parent) {
                    View view = super.onCreateView(parent);
                    view.setBackgroundColor(Color.RED);
                    return view;
                }
            });
    

    You could use this technique to add a button to the default view.

提交回复
热议问题